首页 > 其他 > 详细

LeetCode 942. DI String Match

时间:2018-12-18 13:36:27      阅读:152      评论:0      收藏:0      [点我收藏+]

A simple greedy construction procedure:

- Fill out the seq of ‘I‘ with 0, 1, 2, 3...

- Similarly, for the seq of ‘D‘, fill it out with n, n - 1, n - 2...

- At last, don‘t forget to put last element

class Solution(object):
    def diStringMatch(self, S):
        """
        :type S: str
        :rtype: List[int]
        """
        a, b = 0, len(S)
        r = []
        for c in S:
            if c == I:
                r += [a]
                a += 1
            else:
                r += [b]
                b -= 1
        return r + [a]
        

 

LeetCode 942. DI String Match

原文:https://www.cnblogs.com/tonix/p/10136521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!