In here, I would like to discuss the dynamic set in Leetcode 128 Longest Consecutive Sequence.
This is my solution:
- Put all numbers into set.
- The find the first number of each sequence. The first number is the number without any previous number (n-1) in the set.
- Loop through the next number (n+1). And find out the max count. (Remove the current number from set in order to iterate it again.)
The particular I would discuss is
Remove the current number from set in order to iterate it again.
set.delete(num)
I would say that can be optimize performance. However, base on the leetcode submission result, dynamic changing set is actually a performance penalty.