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[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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy