-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path251.cpp
More file actions
88 lines (82 loc) · 1.97 KB
/
251.cpp
File metadata and controls
88 lines (82 loc) · 1.97 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Vector2D {
private:
vector<vector<int>>::iterator x, y;
vector<int>::iterator z;
public:
Vector2D(vector<vector<int>>& vec) {
x = vec.begin();
y = vec.end();
while (x != y && x->size() == 0) {
x++;
}
if (x == y) return;
z = x->begin();
}
int next() {
hasNext();
return *z++;
}
bool hasNext() {
while (x != y && z == x->end()) {
x++;
if (x == y) break;
z = x->begin();
}
if (x == y) return false;
else return true;
}
};
/**
* Your Vector2D object will be instantiated and called as such:
* Vector2D* obj = new Vector2D(vec);
* int param_1 = obj->next();
* bool param_2 = obj->hasNext();
*/
// V2
// class Vector2D {
// public:
// vector<vector<int>>* vec;
// int row = 0;
// int col = -1;
// Vector2D(vector<vector<int>>& vec) {
// this->vec = &vec;
// findNext();
// }
// void findNext() {
// if (row == (*vec).size()) {
// row = -1;
// col = -1;
// return;
// }
// while (true) {
// if ((*vec)[row].size() != col + 1) {
// col++;
// break;
// }
// else {
// row++;
// col = -1;
// if (row == (*vec).size()) {
// row = -1;
// col = -1;
// break;
// }
// }
// }
// }
// int next() {
// int value = (*vec)[row][col];
// findNext();
// return value;
// }
// bool hasNext() {
// if (row != -1 && col != -1) return true;
// return false;
// }
// };
// /**
// * Your Vector2D object will be instantiated and called as such:
// * Vector2D* obj = new Vector2D(vec);
// * int param_1 = obj->next();
// * bool param_2 = obj->hasNext();
// */