Number of Ways to Select Buildings LeetCode solution in Python
1class Solution:2def numberOfWays(self, s: str) -> int:34temp = []5c0 = 06c1 = 07for char in s:8if char == "0":9c0 += 110else:11c1 += 112temp.append([c0, c1])1314total0 = c015total1 = c11617count = 018for i in range(1, len(s) - 1):1920if s[i] == "0":21m1 = temp[i - 1][1]22m2 = total1 - temp[i][1]23count += m1 * m22425else:26m1 = temp[i - 1][0]27m2 = total0 - temp[i][0]28count += m1 * m229return count