HTMLify
LeetCode - Number of Laser Beams in a Bank - C#
Views: 514 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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; } } |