1
# Runtime: 64 ms (Top 41.88%) | Memory: 14.5 MB (Top 71.25%)
2
class RLEIterator:
3

4
def __init__(self, encoding: List[int]):
5
self.encoding = encoding
6

7
def next(self, n: int) -> int:
8

9
if self.encoding:
10

11
count = self.encoding[0]
12

13
if count >= n:
14
# Partially exhaust and return the current value.
15
self.encoding[0] -= n
16
return self.encoding[1]
17

18
# Exhaust all of current value and continue.
19
self.encoding = self.encoding[2:]
20
return self.next(n - count)
21

22
return -1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0