Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 109 + 7.

&nbsp;
Example 1:

Input: s = "0110111"
Output: 9
Explanation: There are 9 substring in total with only 1's characters.
"1" -&gt; 5 times.
"11" -&gt; 3 times.
"111" -&gt; 1 time.

Example 2:

Input: s = "101"
Output: 2
Explanation: Substring "1" is shown 2 times in s.


Example 3:

Input: s = "111111"
Output: 21
Explanation: Each substring contains only 1's characters.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 105
	s[i] is either '0' or '1'.


class Solution(object):
    def numSub(self, s):
        res, currsum = 0,0
        for digit in s:
            if digit == '0':
                currsum = 0
            else:
                currsum += 1 
                res+=currsum 
        return res % (10**9+7)
class Solution {
    public int numSub(String s) {
        char[] ch = s.toCharArray();
        long count =0;
        long result =0;
        for(int i=0; i<ch.length; i++){
            if(ch[i] == '1'){
                count++;
                result += count;
            }
            else{
                count = 0;
            
            }
        }
        return (int)(result%1000000007);
        
    }
}
class Solution {
    /*
    To calculate the substring the formula is (n*n+1)/2 so just find the range and calculate the substrings.
    */
int mod=1e9+7;
    long calculateNumbeOfSubstrings(string &s,int &l,int &r){
        long range=r-l;
        long ans=range*(range+1)/2;
        return ans;
    }
public:
    int numSub(string s) {
        int ans=0;
        int len=s.size();
        int r=0,l=0;
        while(r<len){
            while(r<len && s[l]!='1'){
                l++;
                r++;
            }
            while(r<len && s[r]!='0'){
                r++;
            }
               ans=(ans+calculateNumbeOfSubstrings(s,l,r))%mod;
                l=r;
        }
        return ans;
    }
};
var numSub = function(s) {
    const mod = Math.pow(10, 9)+7;
    let r = 0, tot = 0;
    
    while (r<s.length) {
        if (s[r]==='1') {
            let tmp = r;
            while (tmp < s.length && s[tmp] === '1') {
                tot += tmp - r + 1;
                tot%=mod;
                tmp++;
            }
            r = tmp;
        }
        r++;
    }
    return tot;
};
Number of Substrings With Only 1s