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

连续的牛群标签序列

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

全部评论

相关推荐

05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
无实习如何秋招上岸
点赞 评论 收藏
分享
舂锋:不能投什么岗都用一份简历,一般都是要看企业的岗位需求来写职业技能或者是项目经历,跟岗位相关的就写多一点。
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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