rewrite leetcode longest consecutive sequence