Skip to content

Commit 63f743b

Browse files
authored
Create minimum-operations-to-make-a-special-number.py
1 parent 4f0ffaa commit 63f743b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space; O(1)
3+
4+
# math, greedy
5+
class Solution(object):
6+
def minimumOperations(self, num):
7+
"""
8+
:type num: str
9+
:rtype: int
10+
"""
11+
lookup = [0]*10
12+
for i in reversed(xrange(len(num))):
13+
if ((num[i] in "05" and lookup[0]) or
14+
(num[i] in "27" and lookup[5])):
15+
return (len(num)-i)-2
16+
lookup[ord(num[i])-ord('0')] = 1
17+
return len(num)-lookup[0]

0 commit comments

Comments
 (0)