aboutsummaryrefslogtreecommitdiff
path: root/other/remove_dupplicate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/remove_dupplicate.cpp')
-rw-r--r--other/remove_dupplicate.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/other/remove_dupplicate.cpp b/other/remove_dupplicate.cpp
new file mode 100644
index 0000000..2628677
--- /dev/null
+++ b/other/remove_dupplicate.cpp
@@ -0,0 +1,22 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ int removeDuplicates(vector<int> &nums) {
+ if (nums.size() == 0)
+ return 0;
+ int ans = 0;
+ for (int i = 1; i < nums.size(); i++) {
+ if (nums[ans] != nums[i])
+ ans++;
+ nums[ans] = nums[i];
+ }
+ return ans + 1;
+ }
+};
+
+int main() {
+ Solution obj;
+ vector<int> nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
+ cout << obj.removeDuplicates(nums);
+}