You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/3201-3300/3234.Count-the-Number-of-Substrings-With-Dominant-Ones/README.md
+36-13Lines changed: 36 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,51 @@
1
1
# [3234.Count the Number of Substrings With Dominant Ones][title]
2
2
3
-
> [!WARNING|style:flat]
4
-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5
-
6
3
## Description
4
+
You are given a binary string `s`.
5
+
6
+
Return the number of substrings with **dominant** ones.
7
+
8
+
A string has **dominant** ones if the number of ones in the string is **greater than or equal to** the **square** of the number of zeros in the string.
7
9
8
10
**Example 1:**
9
11
10
12
```
11
-
Input: a = "11", b = "1"
12
-
Output: "100"
13
-
```
13
+
Input: s = "00011"
14
14
15
-
## 题意
16
-
> ...
15
+
Output: 5
17
16
18
-
## 题解
17
+
Explanation:
19
18
20
-
### 思路1
21
-
> ...
22
-
Count the Number of Substrings With Dominant Ones
23
-
```go
19
+
The substrings with dominant ones are shown in the table below.
20
+
21
+
i j s[i..j] Number of Zeros Number of Ones
22
+
3 3 1 0 1
23
+
4 4 1 0 1
24
+
2 3 01 1 1
25
+
3 4 11 0 2
26
+
2 4 011 1 2
24
27
```
25
28
29
+
**Example 2:**
30
+
31
+
```
32
+
Input: s = "101101"
33
+
34
+
Output: 16
35
+
36
+
Explanation:
37
+
38
+
The substrings with non-dominant ones are shown in the table below.
39
+
40
+
Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.
0 commit comments