Skip to content

Commit c7acf34

Browse files
refactor 594
1 parent 12be2ff commit c7acf34

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
2020
*/
2121
public class _594 {
22-
public int findLHS(int[] nums) {
23-
Map<Integer, Integer> map = new HashMap<>();
24-
for (int i : nums) {
25-
map.put(i, map.getOrDefault(i, 0) + 1);
26-
}
27-
int max = 0;
28-
for (int i = 0; i < nums.length; i++) {
29-
if (map.containsKey(nums[i] + 1)) {
30-
max = Math.max(max, map.get(nums[i]) + map.get(nums[i] + 1));
22+
public static class Solution1 {
23+
public int findLHS(int[] nums) {
24+
Map<Integer, Integer> map = new HashMap<>();
25+
for (int i : nums) {
26+
map.put(i, map.getOrDefault(i, 0) + 1);
27+
}
28+
int max = 0;
29+
for (int i = 0; i < nums.length; i++) {
30+
if (map.containsKey(nums[i] + 1)) {
31+
max = Math.max(max, map.get(nums[i]) + map.get(nums[i] + 1));
32+
}
3133
}
34+
return max;
3235
}
33-
return max;
3436
}
35-
3637
}

src/test/java/com/fishercoder/_594Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
* Created by fishercoder on 5/20/17.
1111
*/
1212
public class _594Test {
13-
private static _594 test;
13+
private static _594.Solution1 solution1;
1414
private static int[] nums;
1515

1616
@BeforeClass
1717
public static void setup() {
18-
test = new _594();
18+
solution1 = new _594.Solution1();
1919
}
2020

2121
@Test
2222
public void test1() {
2323
nums = new int[]{1, 3, 2, 2, 5, 2, 3, 7};
24-
assertEquals(5, test.findLHS(nums));
24+
assertEquals(5, solution1.findLHS(nums));
2525
}
2626
}

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