2
public int longestConsecutive(int[] nums) {3
Set<Integer> storage = new HashSet();5
for (int i = 0; i < nums.length; i++) {11
for (int i = 0; i < nums.length; i++) {13
// check if nums[i] id present in set or not14
// since after checking in set we remove the element from15
// set, there is no double calculation for same sequence16
if (storage.contains(nums[i])) {17
storage.remove(nums[i]);19
int dec = nums[i] - 1;20
int inc = nums[i] + 1;23
// check both ways from nums[i] and calculate24
// tempL. since we are removing elements from25
// set we only calculate once for every sequence.27
while (storage.contains(dec)) {33
while (storage.contains(inc)) {39
maxL = Math.max(maxL, tempL);