Skip to content

Commit 565e47f

Browse files
committed
feat: add solutions to lc problem: No.1784
No.1784.Check if Binary String Has at Most One Segment of Ones
1 parent 408e5bd commit 565e47f

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@ func checkOnesSegment(s string) bool {
9797
}
9898
```
9999

100+
### **TypeScript**
101+
102+
```ts
103+
function checkOnesSegment(s: string): boolean {
104+
let pre = s[0];
105+
for (const c of s) {
106+
if (pre !== c && c === '1') {
107+
return false;
108+
}
109+
pre = c;
110+
}
111+
return true;
112+
}
113+
```
114+
115+
```ts
116+
function checkOnesSegment(s: string): boolean {
117+
return !s.includes('01');
118+
}
119+
```
120+
121+
### **Rust**
122+
123+
```rust
124+
impl Solution {
125+
pub fn check_ones_segment(s: String) -> bool {
126+
!s.contains("01")
127+
}
128+
}
129+
```
130+
100131
### **...**
101132

102133
```

solution/1700-1799/1784.Check if Binary String Has at Most One Segment of Ones/README_EN.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ func checkOnesSegment(s string) bool {
7171
}
7272
```
7373

74+
### **TypeScript**
75+
76+
```ts
77+
function checkOnesSegment(s: string): boolean {
78+
let pre = s[0];
79+
for (const c of s) {
80+
if (pre !== c && c === '1') {
81+
return false;
82+
}
83+
pre = c;
84+
}
85+
return true;
86+
}
87+
```
88+
89+
```ts
90+
function checkOnesSegment(s: string): boolean {
91+
return !s.includes('01');
92+
}
93+
```
94+
95+
### **Rust**
96+
97+
```rust
98+
impl Solution {
99+
pub fn check_ones_segment(s: String) -> bool {
100+
!s.contains("01")
101+
}
102+
}
103+
```
104+
74105
### **...**
75106

76107
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn check_ones_segment(s: String) -> bool {
3+
!s.contains("01")
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function checkOnesSegment(s: string): boolean {
2+
return !s.includes('01');
3+
}

0 commit comments

Comments
 (0)