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

Commit946078b

Browse files
add 1869
1 parent48957fe commit946078b

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1869|[Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1869.java)||Easy|Array, Two Pointers|
1112
|1863|[Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1863.java)||Easy|Backtracking, Recursion|
1213
|1862|[Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1862.java)||Hard|Math|
1314
|1861|[Rotating the Box](https://leetcode.com/problems/rotating-the-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1861.java)|[:tv:](https://youtu.be/2LRnTMOiqSI)|Medium|Array, Two Pointers|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1869 {
4+
publicstaticclassSolution1 {
5+
publicbooleancheckZeroOnes(Strings) {
6+
intzeroes =0;
7+
intones =0;
8+
for (inti =0;i <s.length(); ) {
9+
intstart =i;
10+
while (i <s.length() &&s.charAt(i) =='0') {
11+
i++;
12+
}
13+
if (i >start) {
14+
zeroes =Math.max(zeroes,i -start);
15+
}
16+
start =i;
17+
while (i <s.length() &&s.charAt(i) =='1') {
18+
i++;
19+
}
20+
if (i >start) {
21+
ones =Math.max(ones,i -start);
22+
}
23+
}
24+
returnones >zeroes;
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1869;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1869Test {
10+
privatestatic_1869.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1869.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(true,solution1.checkZeroOnes("1101"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(false,solution1.checkZeroOnes("111000"));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp