python stack solution O(n)


  • 0
    Z
    class Solution(object):
        def findPermutation(self, s):
            result = []
            stack = range(len(s) + 1, 1, -1)
            stack2 = [1]
            for i in range(len(s) + 1):
                if i == len(s) or s[i] == "I":
                    while stack2:
                        result.append(stack2.pop())
                if i != len(s):
                    stack2.append(stack.pop())
            return result
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.