Skip to content

Commit 079c201

Browse files
add 1784
1 parent eaf4941 commit 079c201

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
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+
|1784|[Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1784.java) ||Easy|Greedy|
1112
|1781|[Sum of Beauty of All Substrings](https://leetcode.com/problems/sum-of-beauty-of-all-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1781.java) ||Medium|HashTable, String|
1213
|1780|[Check if Number is a Sum of Powers of Three](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1780.java) ||Medium|Math, Backtracking, Recursion|
1314
|1779|[Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1779.java) ||Easy|Array|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1784 {
4+
public static class Solution1 {
5+
public boolean checkOnesSegment(String s) {
6+
boolean metOne = false;
7+
for (int i = 0; i < s.length(); i++) {
8+
if (s.charAt(i) == '1' && metOne) {
9+
return false;
10+
}
11+
if (s.charAt(i) == '1') {
12+
metOne = true;
13+
while (i < s.length() && s.charAt(i) == '1') {
14+
i++;
15+
}
16+
}
17+
}
18+
return true;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)