FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/C++/flatten-2d-vector.cpp at master · spotpan/LeetCode-Solutions · GitHub
spotpan
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
C++
/
flatten-2d-vector.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (33 loc) · 735 Bytes
Breadcrumbs
LeetCode-Solutions
/
C++
/
flatten-2d-vector.cpp
Copy path
File metadata and controls
38 lines (33 loc) · 735 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
Time: O(1)
//
Space: O(1)
class
Vector2D
{
public:
Vector2D
(vector<vector<
int
>>& vec2d) : vec(vec2d) {
x = vec.
begin
();
if
(x != vec.
end
()) {
y = x->
begin
();
adjustNextIter
();
}
}
int
next
() {
const
auto
ret = *y;
++y;
adjustNextIter
();
return
ret;
}
bool
hasNext
() {
return
x != vec.
end
() && y != x->
end
();
}
void
adjustNextIter
() {
while
(x != vec.
end
() && y == x->
end
()) {
++x;
if
(x != vec.
end
()) {
y = x->
begin
();
}
}
}
private:
vector<vector<
int
>>& vec;
vector<vector<
int
>>::iterator x;
vector<
int
>::iterator y;
};
Back
|
FazBrowse Home
|
New Git URL