首页 > 代码库 > Leetcode#26 Remove Duplicates from Sorted Array

Leetcode#26 Remove Duplicates from Sorted Array

原题地址

 

基本模拟题

 

代码:

 1 int removeDuplicates(int A[], int n) { 2         if (n <= 0) 3             return 0; 4              5         int i = 1; 6         int j = 0; 7          8         while (i < n) { 9             if (A[i] != A[j])10                 A[++j] = A[i];11             i++;12         }13         14         return j + 1;15 }

 

Leetcode#26 Remove Duplicates from Sorted Array