class Solution {
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (n == 0 || n == 1) return n;
int front = 0;
for (int i = 1; i < n; ++i)
{
if (A[i] != A[front])
A[++front] = A[i];
}
return front + 1;
}
};
[Leetcode] Remove Duplicates from Sorted Array
最新推荐文章于 2024-01-02 23:35:28 发布