Skip to content

Commit 946078b

Browse files
add 1869
1 parent 48957fe commit 946078b

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+
package com.fishercoder.solutions;
2+
3+
public class _1869 {
4+
public static class Solution1 {
5+
public boolean checkZeroOnes(String s) {
6+
int zeroes = 0;
7+
int ones = 0;
8+
for (int i = 0; i < s.length(); ) {
9+
int start = 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+
return ones > zeroes;
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1869;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1869Test {
10+
private static _1869.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1869.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(true, solution1.checkZeroOnes("1101"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(false, solution1.checkZeroOnes("111000"));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy