src/main/java/com/leetcode/hashtable/medium/LongestConsecutiveSequence_128.java
public int longestConsecutive(int[] nums) {
      Set<Integer> numsSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());
      Map<Integer, Integer> consecutiveCounts = new HashMap<>();

      int result = 0;
      for (int num : nums) {
        result = Math.max(result, calculateConsecutiveCount(num, numsSet, consecutiveCounts));
      }

      return result;
    }
/*
      O(n) Runtime: 83 ms, faster than 29.40% of Java online submissions for Longest Consecutive Sequence.
      O(n) Memory Usage: 79.1 MB, less than 5.18% of Java online submissions for Longest Consecutive Sequence.
    */
O(n) Runtime: 83 ms, faster than 29.40% of Java online submissions for Longest Consecutive Sequence.
O(n) Memory Usage: 79.1 MB, less than 5.18% of Java online submissions for Longest Consecutive Sequence.
O ( n ) Runtime : 83 ms faster than 29 . 40% of Java online submissions for Longest Consecutive Sequence . O ( n ) Memory Usage : 79 . 1 MB less than 5 . 18% of Java online submissions for Longest Consecutive Sequence .
public int longestConsecutive(int[] nums) {
      Set<Integer> numsSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());
      Map<Integer, Integer> consecutiveCounts = new HashMap<>();
      int result = 0;
      for (int num : nums) {
        result = Math.max(result, calculateConsecutiveCount(num, numsSet, consecutiveCounts));
      }
      return result;
    }
public int longestConsecutive ( int [ ] nums ) { Set < Integer > numsSet = Arrays . stream ( nums ) . boxed ( ) . collect ( Collectors . toSet ( ) ) ; Map < Integer , Integer > consecutiveCounts = new HashMap < > ( ) ; int result = 0 ; for ( int num : nums ) { result = Math . max ( result , calculateConsecutiveCount ( num , numsSet , consecutiveCounts ) ) ; } return result ; }
O(n) Runtime: 83 ms, faster than 29.40% of Java online submissions for Longest Consecutive Sequence.
O ( n ) Runtime : 83 ms faster than 29 . 40% of Java online submissions for Longest Consecutive Sequence .