8000 refactor 565 · ajinkyashendre/Leetcode@53c1e8d · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit 53c1e8d

Browse files
refactor 565
1 parent 53b18ec commit 53c1e8d

File tree

1 file changed

+17
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+17
-15
lines changed

src/main/java/com/fishercoder/solutions/_565.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,25 @@
2828
*/
2929
public class _565 {
3030

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);
4447
}
45-
answer = Math.max(answer, count);
48+
return answer;
4649
}
47-
return answer;
4850
}
4951

5052
}

0 commit comments

Comments
 (0)
0