Skip to content

Commit be3b2c9

Browse files
committed
update: 添加问题“1784.检查二进制字符串字段”的代码(并更新其题解) (#1432)
1784: AC.cpp+py+go+java+rust (#1430) + word(en): 今日昨日 cpp - AC,5.47%,66.87% py - AC,100.00%,40.23% go - AC,100.00%,72.41% java - AC,100.00%,41.57% rust - AC,100.00%,97.06% Signed-off-by: LetMeFly666 <Tisfy@qq.com>
1 parent 95a4c48 commit be3b2c9

10 files changed

Lines changed: 166 additions & 18 deletions

.commitmsg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1784: AC.cpp+py+go+java+rust (#1430) + word(en): 今日昨日
2+
3+
cpp - AC,5.47%,66.87%
4+
py - AC,100.00%,40.23%
5+
go - AC,100.00%,72.41%
6+
java - AC,100.00%,41.57%
7+
rust - AC,100.00%,97.06%
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-07 13:14:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-07 13:14:57
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
bool checkOnesSegment(string s) {
14+
for (int i = 1; i < s.size(); i++) {
15+
if (s[i] == '1' && s[i - 1] == '0') {
16+
return false;
17+
}
18+
}
19+
return true;
20+
}
21+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-07 13:14:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-07 13:16:55
6+
*/
7+
package main
8+
9+
func checkOnesSegment(s string) bool {
10+
for i := 1; i < len(s); i++ {
11+
if s[i - 1] == '0' && s[i] == '1' {
12+
return false
13+
}
14+
}
15+
return true
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-07 13:14:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-07 13:17:43
6+
*/
7+
class Solution {
8+
public boolean checkOnesSegment(String s) {
9+
for (int i = 1; i < s.length(); i++) {
10+
if (s.charAt(i - 1) == '0' && s.charAt(i) == '1') {
11+
return false;
12+
}
13+
}
14+
return true;
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-03-07 13:14:24
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-03-07 13:15:44
6+
'''
7+
class Solution:
8+
def checkOnesSegment(self, s: str) -> bool:
9+
return '01' not in s
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-07 13:14:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-07 13:18:32
6+
*/
7+
impl Solution {
8+
pub fn check_ones_segment(s: String) -> bool {
9+
!s.contains("01")
10+
}
11+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
pub struct Solution;
88

9-
include!("1689-partitioning-into-minimum-number-of-deci-binary-numbers_more-rust.rs"); // 这个fileName是会被脚本替换掉的
9+
include!("1784-check-if-binary-string-has-at-most-one-segment-of-ones_20260307.rs"); // 这个fileName是会被脚本替换掉的
1010

1111
#[derive(Debug, PartialEq, Eq)]
1212
pub struct TreeNode {

Solutions/LeetCode 1784.检查二进制字符串字段.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,85 @@ public:
114114
};
115115
```
116116

117+
#### C++ - 手动find版本
118+
119+
```cpp
120+
/*
121+
* @LastEditTime: 2026-03-07 13:14:57
122+
*/
123+
class Solution {
124+
public:
125+
bool checkOnesSegment(string s) {
126+
for (int i = 1; i < s.size(); i++) {
127+
if (s[i] == '1' && s[i - 1] == '0') {
128+
return false;
129+
}
130+
}
131+
return true;
132+
}
133+
};
134+
```
135+
136+
#### Python
137+
138+
```python
139+
'''
140+
LastEditTime: 2026-03-07 13:15:44
141+
'''
142+
class Solution:
143+
def checkOnesSegment(self, s: str) -> bool:
144+
return '01' not in s
145+
```
146+
147+
#### Java
148+
149+
```java
150+
/*
151+
* @LastEditTime: 2026-03-07 13:17:43
152+
*/
153+
class Solution {
154+
public boolean checkOnesSegment(String s) {
155+
for (int i = 1; i < s.length(); i++) {
156+
if (s.charAt(i - 1) == '0' && s.charAt(i) == '1') {
157+
return false;
158+
}
159+
}
160+
return true;
161+
}
162+
}
163+
```
164+
165+
#### Go
166+
167+
```go
168+
/*
169+
* @LastEditTime: 2026-03-07 13:16:55
170+
*/
171+
package main
172+
173+
func checkOnesSegment(s string) bool {
174+
for i := 1; i < len(s); i++ {
175+
if s[i - 1] == '0' && s[i] == '1' {
176+
return false
177+
}
178+
}
179+
return true
180+
}
181+
```
182+
183+
#### Rust
184+
185+
```rust
186+
/*
187+
* @LastEditTime: 2026-03-07 13:18:32
188+
*/
189+
impl Solution {
190+
pub fn check_ones_segment(s: String) -> bool {
191+
!s.contains("01")
192+
}
193+
}
194+
```
195+
196+
117197
> 同步发文于CSDN,原创不易,转载请附上[原文链接](https://blog.letmefly.xyz/2022/10/03/LeetCode%201784.%E6%A3%80%E6%9F%A5%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AD%97%E6%AE%B5/)哦~
118198
> Tisfy:[https://letmefly.blog.csdn.net/article/details/127150307](https://letmefly.blog.csdn.net/article/details/127150307)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,11 @@ categories: [自用]
18561856
|peninsular|adj. 半岛的|
18571857
|||
18581858
|wrath|n. 怒火|
1859+
|||
1860+
|unaccommodating|adj. 不亲切的,不随和的|
1861+
|||
1862+
|bribery|n. 贿赂,受贿|
1863+
|bamboo shoot|phrase. 竹笋|
18591864

18601865
+ 这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
18611866
+ 也许可以加个AI用最近词编故事功能(返回接口中支持标注所使用单词高亮?)

test.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)