-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode-no6250.py
40 lines (37 loc) · 1.08 KB
/
leetcode-no6250.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
37
38
39
40
class Solution(object):
def bestClosingTime(self, customers):
"""
:type customers: str
:rtype: int
"""
result = []
length = len(customers)
presum = 0
for i in range(length):
later = 0
for j in range(i,length):
later += customers[j]=="Y"
result.append(presum+later)
presum += customers[i]=="N"
result.append(presum)
return result.index(min(result))
class Solution(object):
def bestClosingTime(self, customers):
"""
:type customers: str
:rtype: int
"""
result = []
length = len(customers)
presum = 0
later = customers.count("Y")
for i in range(length):
result.append(presum+(customers[i]=="Y")+later)
presum += customers[i]=="N"
later -= customers[i]=="Y"
result.append(presum)
return result.index(min(result))
t = Solution()
print(t.bestClosingTime("YYNY"))
print(t.bestClosingTime("YYYY"))
print(t.bestClosingTime("NNNN"))