Skip to main content

484 - Find Permutation

KeyValue
Linkhttps://leetcode.com/problems/find-permutation/
LanguagePython 3
Runtime116 ms, faster than 52.25% of Python3 online submissions for Find Permutation
Memory Usage15.4 MB, less than 22.10% of Python3 online submissions for Find Permutation
class Solution:
def findPermutation(self, s: str) -> List[int]:
result, stack = [], []

for i in range(len(s)):
stack.append(i+1)
if s[i] == "I":
while stack: result.append(stack.pop())

stack.append(len(s)+1)
while stack: result.append(stack.pop())

return result