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

Commit85eaa80

Browse files
authored
Merge pull requestneetcode-gh#3109 from Xiaopeng-Sam-Luo/new_branch
create solution to 2348 number of zero filled subarray.js & solution to 0080 remove-duplicates-from-sorted-array-ii.java
2 parents53b3792 +47f9077 commit85eaa80

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

‎java/0080-remove-duplicates-from-sorted-array-ii.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
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+
127
classSolution {
228
publicintremoveDuplicates(int[]nums) {
329
intk =0;
@@ -8,4 +34,5 @@ public int removeDuplicates(int[] nums) {
834
}
935
returnk;
1036
}
11-
}
37+
}
38+

‎javascript/2348-number-of-zero-filled-subarrays.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*@param {number[]} nums
2121
*@return {number}
2222
*/
23+
2324
letzeroFilledSubarray=function(nums){
2425
letresult=0;
2526
letcount=0;
@@ -31,4 +32,4 @@ let zeroFilledSubarray = function (nums) {
3132
}
3233

3334
returnresult;
34-
};
35+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp