现在的位置: 首页 > 综合 > 正文

Leetcode: Remove Duplicates from Sorted Array

2013年12月03日 ⁄ 综合 ⁄ 共 266字 ⁄ 字号 评论关闭

http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/

class Solution {
public:
    int removeDuplicates(int A[], int n) {
        int current=0;
        for(int i=0;i<n;i++){
            if((i+1)<n&&A[i]==A[i+1]) continue;// Don't use A[i]==A[i-1], because A is changing
            A[current++]=A[i];
        }
        return current;
    }
};

抱歉!评论已关闭.