题解 | #连续的牛群标签序列#

连续的牛群标签序列

https://www.nowcoder.com/practice/5db36ae74c274176a0cf9274e9f9ed3e

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;
    }
};

全部评论

相关推荐

01-16 18:34
四川大学 Java
欢迎加入AI:没有啥稳定不稳定,一切都源于业务快速发展还是收缩。我当年一开始去的央企,业务不赚钱,也贼卷,慢慢就开始优化了。。。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务