Number of Substrings With Only 1s LeetCode solution in Java

1
class Solution {
2
public int numSub(String s) {
3
char[] ch = s.toCharArray();
4
long count = 0;
5
long result = 0;
6
for (int i = 0; i < ch.length; i++) {
7
if (ch[i] == '1') {
8
count++;
9
result += count;
10
} else {
11
count = 0;
12
}
13
}
14
return (int) (result % 1000000007);
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0