Solution
C++ []\nint a[100000];\n\nint init = [] {\n    ios_base::sync_with_stdio(false);\n    cin.tie(nullptr);\n    ofstream out("user.out");\n    for (string s; getli
```C++ []\nint a[100000];\n\nint init = [] {\n    ios_base::sync_with_stdio(false);\n    cin.tie(nullptr);\n    ofstream out("user.out");\n    for (string s; getline(cin, s); out << \'\\n\') {\n        if (s.length() == 2) {\n            out << 0;\n            continue;\n        }\n        int n = 0;\n        for (int _i = 1, _n = s.length(); _i < _n; ++_i) {\n            bool _neg = false;\n            if (s[_i] == \'-\') ++_i, _neg = true;\n            int v = s[_i++] & 15;\n            while ((s[_i] & 15) < 10) v = v * 10 + (s[_i++] & 15);\n            if (_neg) v = -v;\n            a[n++] = v;\n        }\n        sort(a, a + n);\n        int ans = 0;\n        for (int i = 0; i < n;) {\n            int i0 = i;\n            for (++i; i < n && a[i - 1] + 1 >= a[i]; ++i);\n            ans = max(ans, a[i - 1] - a[i0] + 1);\n        }\n        out << ans;\n    }\n    out.flush();\n    exit(0);\n    return 0;\n}();\n\nclass Solution {\npublic:\n    int longestConsecutive(vector<int>) { return 999; }\n};\n```\n\n```Python3 []\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        longest = 0\n        num_set = set(nums)\n\n        for n in num_set:\n            if (n-1) not in num_set:\n                length = 1\n                while (n+length) in num_set:\n                    length += 1\n                longest = max(longest, length)\n        \n        return longest\n```\n\n```Java []\nclass Solution {\n    public int longestConsecutive(int[] nums) {int result = 0;\n        if (nums.length > 0) {\n            if (nums.length < 1000) {\n                Arrays.sort(nums);\n                int current = 0;\n                for (int i = 1; i < nums.length; i++) {\n                    if (nums[i] != nums[i - 1]) {\n                        if (nums[i] - nums[i - 1] == 1) {\n                            current++;\n                        } else {\n                            if (current + 1 > result) {\n                                result = current + 1;\n                            }\n                            current = 0;\n                        }\n                    }\n                }\n                if (current + 1 > result) {\n                    result = current + 1;\n                }\n            } else {\n                int min = Integer.MAX_VALUE;\n                int max = Integer.MIN_VALUE;\n                for (int num : nums) {\n                    if (num > max) {\n                        max = num;\n                    }\n                    if (num < min) {\n                        min = num;\n                    }\n                }\n                byte[] bits = new byte[max - min + 1];\n                for (int num : nums) {\n                    bits[num - min] = 1;\n                }\n                int current = 0;\n                for (byte bit : bits) {\n                    if (bit > 0) {\n                        current++;\n                    } else {\n                        if (current > result) {\n                            result = current;\n                        }\n                        current = 0;\n                    }\n                }\n                if (current > result) {\n                    result = current;\n                }\n            }\n        }\n        return result;\n    }\n}\n```\n
['C++', 'Java', 'Python3']