-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
52 lines (47 loc) · 1.01 KB
/
main.cpp
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
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
class Solution {
public:
int arrayNesting(vector<int>& nums) {
int maxx = 1;
bool vis[nums.size() + 10];
memset(vis, false, sizeof(vis));
for (int i = 0; i < nums.size(); i ++) {
int step = 0;
int j = i;
while (!vis[j]) {
vis[j] = 1;
j = nums[j];
step += 1;
}
maxx = max(maxx, step);
}
return maxx;
}
};
#ifdef LZS
int main() {
Solution s;
[& s] () {
std::vector<int> v {5,4,0,3,1,6,2};
cout << s.arrayNesting(v) << endl;
}();
[& s] () {
std::vector<int> v {0, 1, 2};
cout << s.arrayNesting(v) << endl;
}();
[& s] () {
std::vector<int> v {1, 2, 0};
cout << s.arrayNesting(v) << endl;
}();
return 0;
}
#endif