题解 | #扑克牌顺子#

扑克牌顺子

http://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4

class Solution {
public:
    bool IsContinuous( vector<int> numbers ) {
        sort(numbers.begin(), numbers.end());
        int jokerNumber = 0;
        int pre = numbers[0];
        if(pre == 0)
            jokerNumber++;
        for(int i = 1; i < numbers.size(); i++) {
            int cur = numbers[i];
            if(cur == 0)
                jokerNumber++;
            else {
                if(cur == pre)
                    return false;
            }
            if(jokerNumber > 4)
                return false;
            int gap = cur - pre;
            while(gap > 1 && jokerNumber && pre > 0) {
                jokerNumber--;
                gap--;
            }
            if(pre > 0 && gap > 1)
                return false;
            pre = cur;
        }
        return true;
    }
};
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务