Index: [Leetcode] leetcode key index (C++/JAVA/PYTHON/SQL)
Github:https://github.com/illuz/leetcode
026. Remove duplicates from Sorted Array (easy)
links:
Title: https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
Code (GitHub): Https://github.com/illuz/leetcode
Test Instructions:
To an ordered sequence, delete the repeating element.
Analysis:
If you can open an array to save it is very easy. But this problem doesn't allow you to use extra space.
But it's not difficult, just maintain a new coordinate.
STL with C + + can only be a sentence: With the unique
implementation of the function, the size of the distance
calculation.
Java and Python are written in the same way as C + +, not here.
Code:
C + +: (analog)
Class Solution {public: int removeduplicates (int a[], int n) {if (!n) return 0;int ret = 1;for (int i = 1; i < n; i+ +) if (a[i]! = A[i-1]) a[ret++] = A[i];return ret;}};
C + +: (STL)
Class Solution {public: int removeduplicates (int a[], int n) { return distance (A, unique (a, a + N));} };
[Leetcode] 026. Remove Duplicates from Sorted Array (Easy) (C++/java)