标签:
原题链接:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
很简单的题,维持一个front标志和prev维持之前的值,边扫边比较。
class Solution { public: int removeDuplicates(int A[], int n) { if (n <= 0) return n; int prev = INT_MIN; int front = 0; int idx = 0; while (idx < n) { if (A[idx] != prev) { A[front] = A[idx]; prev = A[front]; ++front; } ++idx; } return front; } };
[Leetcode] 26 - Remove Duplicates from Sorted Array
标签:
原文地址:http://blog.csdn.net/algorithmengine/article/details/43196471