Skip to content

Commit 16e7580

Browse files
adam.linadam.lin
adam.lin
authored and
adam.lin
committed
removeDuplicates
1 parent c1ffa29 commit 16e7580

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

26_removeDuplicates.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <vector>
2+
3+
class Solution {
4+
public:
5+
int removeDuplicates(std::vector<int>& nums) {
6+
if (nums.empty())
7+
{
8+
return 0;
9+
}
10+
int count = 0;
11+
for (int i = 0; i <= nums.size() - 1; i++)
12+
{
13+
if (nums[i] != nums[count])
14+
{
15+
count++;
16+
nums[count] = nums[i];
17+
}
18+
}
19+
return ++count;
20+
}
21+
};

0 commit comments

Comments
 (0)