Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8976cf8

Browse files
Sam  LuoSam  Luo
Sam Luo
authored and
Sam Luo
committed
create solution for 0080-remove-duplicates-from-sorted-array-ii
1 parent2c10e7f commit8976cf8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Time Complexity: O(n);
3+
* Space Complexity: O(1);
4+
*/
5+
6+
classSolution {
7+
publicintremoveDuplicates(int[]nums) {
8+
intcount =1;
9+
intindex1 =0;
10+
for(inti =1;i <nums.length;i++){
11+
if(nums[i] !=nums[index1]){
12+
count =1;
13+
index1 ++;
14+
nums[index1] =nums[i];
15+
}else{
16+
count ++;
17+
if(count <=2){
18+
index1 ++;
19+
nums[index1] =nums[i];
20+
}
21+
};
22+
};
23+
returnindex1 +1;
24+
}
25+
}
26+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp