首页 > 其他 > 详细

【leetcode】900. RLE Iterator

时间:2018-09-12 14:50:05      阅读:254      评论:0      收藏:0      [点我收藏+]

题目如下:

技术分享图片

解题思路:非常简单的题目,直接递归就行了。

代码如下:

class RLEIterator(object):
    def __init__(self, A):
        """
        :type A: List[int]
        """
        self.l = A[::]

    def next(self, n):
        """
        :type n: int
        :rtype: int
        """
        while n > 0 and len(self.l) > 0:
            if self.l[0] >= n:
                self.l[0] -= n
                return self.l[1]
            else:
                n -= self.l[0]
                del self.l[0]
                del self.l[0]
                return self.next(n)
        return -1

 

【leetcode】900. RLE Iterator

原文:https://www.cnblogs.com/seyjs/p/9613932.html

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