@@ -69,74 +69,6 @@ Each call to RLEIterator.next(int n) will have 1 <= n <= 10^9.
6969## 代码
7070
7171``` js
72- /*
73- * @lc app=leetcode id=900 lang=javascript
74- *
75- * [900] RLE Iterator
76- *
77- * https://leetcode.com/problems/rle-iterator/description/
78- *
79- * algorithms
80- * Medium (49.03%)
81- * Total Accepted: 11.6K
82- * Total Submissions: 23.5K
83- * Testcase Example: '["RLEIterator","next","next","next","next"]\n[[[3,8,0,9,2,5]],[2],[1],[1],[2]]'
84- *
85- * Write an iterator that iterates through a run-length encoded sequence.
86- *
87- * The iterator is initialized by RLEIterator(int[] A), where A is a run-length
88- * encoding of some sequence. More specifically, for all even i, A[i] tells us
89- * the number of times that the non-negative integer value A[i+1] is repeated
90- * in the sequence.
91- *
92- * The iterator supports one function: next(int n), which exhausts the next n
93- * elements (n >= 1) and returns the last element exhausted in this way. If
94- * there is no element left to exhaust, next returns -1 instead.
95- *
96- * For example, we start with A = [3,8,0,9,2,5], which is a run-length encoding
97- * of the sequence [8,8,8,5,5]. This is because the sequence can be read as
98- * "three eights, zero nines, two fives".
99- *
100- *
101- *
102- * Example 1:
103- *
104- *
105- * Input: ["RLEIterator","next","next","next","next"],
106- * [[[3,8,0,9,2,5]],[2],[1],[1],[2]]
107- * Output: [null,8,8,5,-1]
108- * Explanation:
109- * RLEIterator is initialized with RLEIterator([3,8,0,9,2,5]).
110- * This maps to the sequence [8,8,8,5,5].
111- * RLEIterator.next is then called 4 times:
112- *
113- * .next(2) exhausts 2 terms of the sequence, returning 8. The remaining
114- * sequence is now [8, 5, 5].
115- *
116- * .next(1) exhausts 1 term of the sequence, returning 8. The remaining
117- * sequence is now [5, 5].
118- *
119- * .next(1) exhausts 1 term of the sequence, returning 5. The remaining
120- * sequence is now [5].
121- *
122- * .next(2) exhausts 2 terms, returning -1. This is because the first term
123- * exhausted was 5,
124- * but the second term did not exist. Since the last term exhausted does not
125- * exist, we return -1.
126- *
127- *
128- *
129- * Note:
130- *
131- *
132- * 0 <= A.length <= 1000
133- * A.length is an even integer.
134- * 0 <= A[i] <= 10^9
135- * There are at most 1000 calls to RLEIterator.next(int n) per test case.
136- * Each call to RLEIterator.next(int n) will have 1 <= n <= 10^9.
137- *
138- *
139- */
14072/**
14173 * @param {number[]} A
14274 */
0 commit comments