We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c10e7f commit 8976cf8Copy full SHA for 8976cf8
java/0080-remove-duplicates-from-sorted-array-ii.java
@@ -0,0 +1,26 @@
1
+/*
2
+ * Time Complexity: O(n);
3
+ * Space Complexity: O(1);
4
+ */
5
+
6
+class Solution {
7
+ public int removeDuplicates(int[] nums) {
8
+ int count = 1;
9
+ int index1 = 0;
10
+ for(int i = 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
19
20
+ }
21
+ };
22
23
+ return index1 + 1;
24
25
+}
26
0 commit comments