Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b5c8df

Browse files
solved leetcode daily challenge, array nesting
See: Why: How: Tags:
1 parent b39815d commit 3b5c8df

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

‎LeetCode/Array_Nesting/main.cxx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## Array Nesting
9+
10+
*/
11+
class Solution {
12+
public:
13+
int arrayNesting(vector<int>& nums) {
14+
unordered_map<int,bool> visited;
15+
int ret= 0;
16+
for (int i = 0; i < nums.size();i++){
17+
if (visited[nums[i]]) continue;
18+
visited[nums[i]]=true;
19+
int length = 1;
20+
int last = nums[i];
21+
while(1){
22+
if (!visited[nums[last]]){
23+
visited[nums[last]]=true;
24+
last = nums[last];
25+
length++;
26+
}else{
27+
break;
28+
}
29+
}
30+
ret = max(ret,length);
31+
}
32+
return ret;
33+
}
34+
};
35+
36+
37+
38+
39+
//// END
40+
struct T{
41+
42+
};
43+
44+
TEST(Solution,test){
45+
T ts[] = {
46+
{
47+
48+
},
49+
{
50+
51+
},
52+
53+
};
54+
55+
56+
for (T t : ts){
57+
Solution solution;
58+
59+
}
60+
}
61+
62+
int main() {
63+
testing::InitGoogleTest();
64+
65+
return RUN_ALL_TESTS();
66+
}
67+
68+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /