Skip to content

Commit bfc693e

Browse files
authored
Added "Remove duplicates from sorted array"
Added aother problem from the top interview problems list
1 parent 81f277c commit bfc693e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int removeDuplicates(vector<int>& nums) {
4+
if(nums.size()<=1) return nums.size();
5+
int i=0,n=nums.size(),greater_than=0,size;
6+
while(i<n)
7+
{
8+
9+
size=greater_than+1;
10+
i++;
11+
while(i<n && nums[i]<=nums[greater_than])
12+
i++;
13+
if(i<n)
14+
{
15+
swap(nums[size],nums[i]);
16+
greater_than=size;
17+
}
18+
19+
}
20+
return size;
21+
}
22+
};

0 commit comments

Comments
 (0)