-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path26.cpp
47 lines (41 loc) · 881 Bytes
/
26.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cassert>
#include <gtest/gtest.h>
#include <vector>
using namespace std;
class Solution {
public:
int removeDuplicates(vector<int> &nums)
{
if (nums.empty())
return 0;
int i = 0;
int j = 1;
while (j < nums.size()) {
if (nums[i] == nums[j]) {
j++;
}
else {
nums[++i] = nums[j++];
}
}
return i + 1;
}
};
class Testing : public testing::Test {
public:
Solution solution;
void SetUp() {}
void TearDown() {}
};
TEST_F(Testing, Case1)
{
vector<int> nums = {1, 1, 2};
int result = 2;
EXPECT_EQ(solution.removeDuplicates(nums), result);
}
TEST_F(Testing, Case2)
{
vector<int> nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
int result = 5;
EXPECT_EQ(solution.removeDuplicates(nums), result);
}