Skip to content

Commit 975347b

Browse files
committed
Updated longest consecutive sequence
1 parent 54bbf0b commit 975347b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Hard/LongestConsecutiveSeq.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import java.util.HashMap;
1+
import java.util.*;
22

33
/**
44
* Given an unsorted array of integers, find the length of the longest
@@ -15,8 +15,9 @@
1515
*/
1616
class LongestConsecutiveSeq {
1717
public static void main(String[] args) {
18+
LongestConsecutiveSeq l = new LongestConsecutiveSeq();
1819
int[] a = {100, 4, 200, 1, 3, 2};
19-
System.out.println(longestConsecutive(a));
20+
System.out.println(l.longestConsecutive(a));
2021
}
2122

2223
/**
@@ -27,7 +28,7 @@ public static void main(String[] args) {
2728
* Put all possible ranges into map
2829
* including num[i] ~ num[i], low ~ upp, upp ~ low
2930
*/
30-
public static int longestConsecutive(int[] num) {
31+
public int longestConsecutive(int[] num) {
3132
if (num == null || num.length == 0) return 0;
3233
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
3334
int maxLen = 0;
@@ -45,4 +46,4 @@ public static int longestConsecutive(int[] num) {
4546
}
4647
return maxLen;
4748
}
48-
}
49+
}

0 commit comments

Comments
 (0)