Normally the best time cost is 20ms in C++ enclosed with two different solutions
class Solution\n    {\n        public:\n            //AC - 24ms - bottom-up method;\n            int longestConsecutive(vector<int>& nums) \n            {\n    
    class Solution\n    {\n        public:\n            //AC - 24ms - bottom-up method;\n            int longestConsecutive(vector<int>& nums) \n            {\n                int maxCount = 0, lCount = 0, rCount = 0;\n                unordered_map<int, int> count_map;\n                for(int i = 0; i < nums.size(); ++i)\n                {\n                    if(!count_map[nums[i]])\n                    {\n                        int lCount = count_map[nums[i]-1];\n                        int rCount = count_map[nums[i]+1];\n                        int sum = lCount+rCount+1;\n                        count_map[nums[i]] = count_map[nums[i]-lCount] = count_map[nums[i]+rCount] = sum;\n                        maxCount = max(maxCount, sum);\n                    }\n                }\n                return maxCount;\n            }\n    \n            //AC - 20ms - blood spreading into two directions;\n            int longestConsecutive(vector<int>& nums)\n            {\n                unordered_set<int> set(nums.begin(), nums.end());\n                int ret = 1;\n                for(auto &n: nums)\n                {\n                    if(!set.count(n)) continue;\n                    set.erase(n);\n                    int pre=n-1, next=n+1;\n                    while(set.count(pre)) set.erase(pre--);\n                    while(set.count(next)) set.erase(next++);\n                    ret = max(ret, next-pre-1);\n                }\n                return ret;\n            }\n    };
['C++']