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

连续的牛群标签序列

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

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 13:15
点赞 评论 收藏
分享
舂锋:不能投什么岗都用一份简历,一般都是要看企业的岗位需求来写职业技能或者是项目经历,跟岗位相关的就写多一点。
点赞 评论 收藏
分享
07-11 11:15
中南大学 Java
好可爱的hr姐姐哈哈哈哈
黑皮白袜臭脚体育生:兄弟们貂蝉在一起,吕布开了
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务