Number of Laser Beams in a Bank

class Solution {
    public int numberOfBeams(String[] bank) {
        int n = bank.length;
        int pre = -1;
        int res = 0;
        for(int i = 0; i < n; i++){
            int count = 0;
            for(int j = 0; j < bank[i].length(); j++) {
                if(bank[i].charAt(j) == '1')
                    count++;
            }
            if(count == 0)
                continue;
            if(pre == -1)
                pre = count;
            else{
                res += pre * count;
                pre = count;
            }
                
        }
        return res;
    }
}