MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / RLEIterator

Class RLEIterator

Design/RLEIterator.py:54–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53"""
54class RLEIterator(object):
55
56 def __init__(self, A):
57 """
58 :type A: List[int]
59 """
60 self.a = A
61
62 def next(self, n):
63 """
64 :type n: int
65 :rtype: int
66 """
67 for i in range(0, len(self.a), 2):
68 if self.a[i] > 0:
69 if self.a[i] - n >= 0:
70 self.a[i] -= n
71 return self.a[i+1]
72 else:
73 t = self.a[i]
74 self.a[i] -= n
75 n -= t
76 return -1
77
78
79# Your RLEIterator object will be instantiated and called as such:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected