题解 | #扑克牌顺子#

扑克牌顺子

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

class Solution {
  public:
    bool IsContinuous( vector<int> numbers ) {
        unordered_set<int> hashtable;
        int ma = 0, mi = 14;
        for (int i = 0; i < 5; ++i) {
            // 如果是大小王则不作统计
            if (numbers[i] == 0)   continue;
            // 不能重复出现
            if (hashtable.count(numbers[i])) return false;
            hashtable.insert(numbers[i]);
            ma = max(ma, numbers[i]);
            mi = min(mi, numbers[i]);
        }
        // 最后判断最大值与最小值之差是否小于5
        return ma - mi < 5;
    }
};

全部评论

相关推荐

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