leetcode - 942 - 增减字符串匹配

class Solution:
    def diStringMatch(self, S):
        """
        :type S: str
        :rtype: List[int]
        """
        N = len(S)
        L = []
        a = 0
        for i in range(N):
            if S[i] == "I":
                L.append(a)
                a += 1
            else:
                L.append(N)
                N -= 1
        L.append(a)
        return L
            

猜你喜欢

转载自blog.csdn.net/hustwayne/article/details/84501774