-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2055 Plates Between Candles.py
36 lines (34 loc) · 1.11 KB
/
2055 Plates Between Candles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution(object):
def platesBetweenCandles(self, s, queries):
"""
:type s: str
:type queries: List[List[int]]
:rtype: List[int]
"""
output = []
for query in queries:
count = 0
left = query[0]
right = query[1]
while left < len(s) and s[left] == "*":
left += 1
while right > 0 and s[right] == "*":
right -= 1
while left <= right:
if left == right:
if s[left] == "*":
count += 1
left += 1
right -= 1
else:
if s[left] == "*":
count += 1
left += 1
if s[right] == "*":
count += 1
right -= 1
output.append(count)
return output
obj = Solution()
# print(obj.platesBetweenCandles("**|**|***|", [[2,5],[5,9]]))
print(obj.platesBetweenCandles("***|**|*****|**||**|*", [[1,17],[4,5],[14,17],[5,11],[15,16]]))