2019年3月15日 942. DI String Match

感觉不是很难的题,控制一下变量和范围就OK了。

class Solution(object):
    def diStringMatch(self, S):
        """
        :type S: str
        :rtype: List[int]
        """
        x1 = 10000
        x2 = 10000
        ret = [10000]
        for i in S:
            if i == 'I':
                x1 += 1
                ret.append(x1)
            else:
                x2 -= 1
                ret.append(x2)
                
        x = min(ret)
        #print ret, x
        ret = [i - x for i in ret]
        
        return ret
posted @ 2019-03-15 15:23  miuc  阅读(111)  评论(0编辑  收藏  举报