代码改变世界

leetcode - Remove Duplicates from Sorted Array

2013-10-20 10:16  张汉生  阅读(123)  评论(0编辑  收藏  举报

 1 class Solution {
 2 public:
 3     int removeDuplicates(int A[], int n) {
 4         // Note: The Solution object is instantiated only once and is reused by each test case.
 5         if (n<=1)
 6             return n;
 7         int last = 1;
 8         for (int i=1; i<n; i++){
 9             if (A[i]!=A[i-1])
10                 A[last++] = A[i];
11         }
12         return last;
13     }
14 };