Created
August 28, 2014 01:52
-
-
Save walkingtospace/aa68010f8da1c9331451 to your computer and use it in GitHub Desktop.
remove-duplicates-from-sorted-array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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