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