Skip to content

Commit 626ffcd

Browse files
committed
Runtime: 3 ms (Top 82.50%) | Memory: 7.5 MB (Top 36.47%)
1 parent 3110e2f commit 626ffcd

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1+
// Runtime: 3 ms (Top 82.50%) | Memory: 7.5 MB (Top 36.47%)
12
/*
23
* Below is the interface for Iterator, which is already defined for you.
34
* **DO NOT** modify the interface for Iterator.
45
*
5-
* class Iterator {
6-
* struct Data;
7-
* Data* data;
8-
* public:
9-
* Iterator(const vector<int>& nums);
10-
* Iterator(const Iterator& iter);
6+
* class Iterator {
7+
* struct Data;
8+
* Data* data;
9+
* public:
10+
* Iterator(const vector<int>& nums);
11+
* Iterator(const Iterator& iter);
1112
*
12-
* // Returns the next element in the iteration.
13-
* int next();
13+
* // Returns the next element in the iteration.
14+
* int next();
1415
*
15-
* // Returns true if the iteration has more elements.
16-
* bool hasNext() const;
17-
* };
16+
* // Returns true if the iteration has more elements.
17+
* bool hasNext() const;
18+
* };
1819
*/
1920

2021
class PeekingIterator : public Iterator {
2122
public:
2223
int _nextVal;
2324
bool _hasNext;
24-
PeekingIterator(const vector<int>& nums) : Iterator(nums) {
25-
// Initialize any member here.
26-
// **DO NOT** save a copy of nums and manipulate it directly.
27-
// You should only use the Iterator interface methods.
25+
PeekingIterator(const vector<int>& nums) : Iterator(nums) {
26+
// Initialize any member here.
27+
// **DO NOT** save a copy of nums and manipulate it directly.
28+
// You should only use the Iterator interface methods.
2829
_nextVal = 0;
2930
_hasNext = Iterator::hasNext();
3031
if (_hasNext)
3132
_nextVal = Iterator::next();
32-
}
33-
33+
}
34+
3435
// Returns the next element in the iteration without advancing the iterator.
35-
int peek() {
36+
int peek() {
3637
return (_nextVal);
37-
}
38-
38+
}
3939

40-
// hasNext() and next() should behave the same as in the Iterator interface.
41-
// Override them if needed.
42-
int next() {
40+
// hasNext() and next() should behave the same as in the Iterator interface.
41+
// Override them if needed.
42+
int next() {
4343
int tmp = _nextVal;
44-
44+
4545
_hasNext = Iterator::hasNext();
4646
if (_hasNext)
4747
_nextVal = Iterator::next();
4848
return (tmp);
49-
}
50-
51-
bool hasNext() const {
49+
}
50+
51+
bool hasNext() const {
5252
return (_hasNext);
53-
}
53+
}
5454
};

0 commit comments

Comments
 (0)