[JAVA] Simple O(n) solution using HashSet
\nKINDLY PLEASE UPVOTE IF YOU FIND IT HELPFUL \n\n\n```\nclass Solution {\n    public int longestConsecutive(int[] nums) {\n      Set  set = new HashSet ();\n  
```\nKINDLY PLEASE UPVOTE IF YOU FIND IT HELPFUL \n```\n\n```\nclass Solution {\n    public int longestConsecutive(int[] nums) {\n      Set <Integer> set = new HashSet <Integer>();\n      for(int n : nums)\n        set.add(n);\n      \n      int streak = 0;\n      for(int n : nums) {\n        if(!set.contains(n - 1)) {\n          int currNum = n;\n          int currStreak = 1;\n          \n          while(set.contains(currNum + 1)) {\n            currNum ++;\n            currStreak ++;\n          }\n\t\t  \n          streak = Math.max(streak , currStreak);\n      }\n    }\n      return streak;\n  }\n}\n
['Ordered Set', 'Java']