-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2086.py
More file actions
24 lines (23 loc) · 719 Bytes
/
2086.py
File metadata and controls
24 lines (23 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
@staticmethod
def minimumBuckets(hamsters: str) -> int:
'''
. - empty
! - food
H - hungry hamster
'''
hamsters = [*hamsters]
food = 0
for i in range(len(hamsters)):
if hamsters[i] == 'H':
if i - 1 >= 0 and hamsters[i - 1] == '!':
pass
elif i + 1 < len(hamsters) and hamsters[i + 1] == '.':
food += 1
hamsters[i + 1] = '!'
elif i - 1 >= 0 and hamsters[i - 1] == '.':
food += 1
hamsters[i - 1] = '!'
else:
return -1
return food