Skip to content

Commit 3672dc8

Browse files
authored
Create di-string-match.py
1 parent 620c4b4 commit 3672dc8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python/di-string-match.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def diStringMatch(self, S):
6+
"""
7+
:type S: str
8+
:rtype: List[int]
9+
"""
10+
result = []
11+
left, right = 0, len(S)
12+
for c in S:
13+
if c == 'I':
14+
result.append(left)
15+
left += 1
16+
else:
17+
result.append(right)
18+
right -= 1
19+
result.append(left)
20+
return result

0 commit comments

Comments
 (0)