class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param tag int整型vector 
     * @return int整型
     */
    int longestConsecutive(vector<int>& tag) {
        // write code here
        set<int> s(tag.begin(), tag.end());
        int length = 1, lengthmax = 0;

        set<int>::iterator it = s.begin();
        while (true)
        {
            if (*it - *(++it) == -1)
                ++length;
            else  
                length = 1;
            if (it == s.end()) break;
            lengthmax = max(length, lengthmax);
        }
        return lengthmax;
    }
};