File tree Expand file tree Collapse file tree 1 file changed +17
-15
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Original file line number Diff line number Diff line change 28
28
*/
29
29
public class _565 {
30
30
31
- public int arrayNesting (int [] nums ) {
32
- if (nums == null || nums .length == 0 ) {
33
- return 0 ;
34
- }
35
- boolean [] visited = new boolean [nums .length ];
36
- int answer = 0 ;
37
- for (int i : nums ) {
38
- int count = 0 ;
39
- int j = i ;
40
- while (j >= 0 && j < nums .length && !visited [j ]) {
41
- count ++;
42
- visited [j ] = true ;
43
- j = nums [j ];
31
+ public static class Solution1 {
32
+ public int arrayNesting (int [] nums ) {
33
+ if (nums == null || nums .length == 0 ) {
34
+ return 0 ;
35
+ }
36
+ boolean [] visited = new boolean [<
9707
span class=pl-s1>nums.length ];
37
+ int answer = 0 ;
38
+ for (int i : nums ) {
39
+ int count = 0 ;
40
+ int j = i ;
41
+ while (j >= 0 && j < nums .length && !visited [j ]) {
42
+ count ++;
43
+ visited [j ] = true ;
44
+ j = nums [j ];
45
+ }
46
+ answer = Math .max (answer , count );
44
47
}
45
- answer = Math . max ( answer , count ) ;
48
+ return answer ;
46
49
}
47
- return answer ;
48
50
}
49
51
50
52
}
You can’t perform that action at this time.
0 commit comments