Leetcode 979 Solution

This article provides solution to leetcode question 979 (di-string-match)

https://leetcode.com/problems/di-string-match

Solution

class Solution: def diStringMatch(self, S: str) -> List[int]: l = 0 r = len(S) i = 0
ans = [] while l < r: if S[i] == 'I': ans.append(l) l += 1 else: ans.append(r) r -= 1 i += 1 ans.append(l) return ans