HTMLify

LeetCode - Number of Laser Beams in a Bank - C#
Views: 158 | Author: abh
public class Solution {
    public int NumberOfBeams(string[] bank) {
        int pre_lesers = 0;
        int beams = 0;
        foreach (string floor in bank){
            int current_lesers = 0;
            foreach (char c in floor){
                if (c == '1')
                    current_lesers += 1;
            }
            if (current_lesers==0)
                continue;
            beams += pre_lesers * current_lesers;
            pre_lesers = current_lesers;
        }
    return beams;
    }
}

Comments

abh 2024-01-03 11:47

This is my first C# code