Python O(n)


  • 0
    R
    class Solution(object):
        def findPermutation(self, s):
            n = len(s)
            ret = range(1, n+2)
            i = 0
            while i<n:
                if s[i] == 'I':
                    i += 1
                else:
                    start = i
                    while i<n and s[i] == 'D':
                        i += 1
                    ret[start:i+1] = ret[start:i+1][::-1]
            return ret
    

Log in to reply
 

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