Skip to content

Commit 992e8d4

Browse files
committed
Update and rename removeDuplicates.cpp to remove-duplicates-from-sorted-array.cpp
1 parent c62c72d commit 992e8d4

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int removeDuplicates(vector<int>& nums) {
7+
int last = -1;
8+
for (const auto& num : nums) {
9+
if (last == -1 || nums[last] != num) {
10+
nums[++last] = num;
11+
}
12+
}
13+
14+
return last + 1;
15+
}
16+
};

C++/removeDuplicates.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)