Skip to content

Instantly share code, notes, and snippets.

@walkingtospace
Created August 28, 2014 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkingtospace/aa68010f8da1c9331451 to your computer and use it in GitHub Desktop.
Save walkingtospace/aa68010f8da1c9331451 to your computer and use it in GitHub Desktop.
remove-duplicates-from-sorted-array
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
/*
똑같은 문제인 https://oj.leetcode.com/problems/remove-element/의 유사판
16라인 한줄만 고치고 accepted
*/
class Solution {
public:
int removeDuplicates(int A[], int n) {
if(n <= 0) {
return n;
}
int jumpCnt = 0;
for(int i=0; i<n ; ++i) {
while(i+jumpCnt+1 < n && A[i+jumpCnt] == A[i+jumpCnt+1]) {
++jumpCnt;
}
A[i] = A[i+jumpCnt];
}
return n-jumpCnt;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment