Skip to content

Commit b2bea98

Browse files
authored
Update minimum-number-of-pushes-to-type-word-i.py
1 parent 4598470 commit b2bea98

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Python/minimum-number-of-pushes-to-type-word-i.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
# Time: O(4)
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def minimumPushes(self, word):
7+
"""
8+
:type word: str
9+
:rtype: int
10+
"""
11+
def ceil_divide(a, b):
12+
return (a+b-1)//b
13+
14+
result, cnt = 0, len(word)
15+
for i in xrange(1, 1+ceil_divide(cnt, (9-2+1))):
16+
g = min(cnt, (9-2+1))
17+
cnt -= g
18+
result += i*g
19+
return result
20+
21+
122
# Time: O(26)
223
# Space: O(26)
3-
424
import collections
525

626

727
# freq table, greedy
8-
class Solution(object):
28+
class Solution2(object):
929
def minimumPushes(self, word):
1030
"""
1131
:type word: str

0 commit comments

Comments
 (0)