@@ -15,7 +15,7 @@ public class Geegong {
1515 * - O (N) : sorting된걸 한번 더 순회
1616 * Space complexity : O(N) -> hash set
1717 * @param nums
18- * @return
18+ * @return int
1919 */
2020 public int longestConsecutive (int [] nums ) {
2121 if (nums .length == 0 ) {
@@ -46,61 +46,8 @@ public int longestConsecutive(int[] nums) {
4646 prev = sortedNums [index ];
4747 }
4848
49-
50-
5149 return Math .max (currentLength , maxLength );
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
6750 }
68- // HashSet<Integer> setOfNums = new HashSet<>();
69- // // key : startIndex , value : length
70- // Map<Integer, Integer> lengthMap = new HashMap<>();
71- //
72- // // sort..? 를 해야될까 싶음..
73- //
74- // // initialize
75- // for (int num : nums) {
76- // setOfNums.add(num);
77- // }
78- //
79- // Integer longest = 0;
80- //
81- // for (Integer num : setOfNums) {
82- // int length = iterate(setOfNums, num, 0, lengthMap);
83- // longest = Math.max(longest, length);
84- // }
85- //
86- // return longest;
87- // }
88- //
89- // public Integer iterate(HashSet<Integer> hashSet, int currIndex, int currLength, Map<Integer, Integer> lengthMap) {
90- // if (lengthMap.containsKey(currIndex)) {
91- // return lengthMap.get(currIndex);
92- // }
93- //
94- // if (hashSet.contains(currIndex)) {
95- // currLength++;
96- // return iterate(hashSet, currIndex+1, currLength, lengthMap);
97- //
98- // } else {
99- // lengthMap.put(currIndex, currLength);
100- // return currLength;
101- // }
102- //
103- // }
10451
10552}
10653
0 commit comments