剑指offer 扑克牌顺子

class Solution {
public:
    bool IsContinuous( vector<int> numbers ) {
        if(numbers.empty()) return false;
        set<int> s;
        for(int num: numbers){
            if(num != 0){
                if(s.find(num) != s.end()) return false;
                s.emplace(num);
            }
        }
        int gap = *max_element(s.begin(), s.end()) - *min_element(s.begin(), s.end());
        return gap <= 4;
    }
};
# -*- coding:utf-8 -*-
class Solution:
    def IsContinuous(self, numbers):
        # write code here
        if not numbers:
            return False
        s = set()
        for num in numbers:
            if num == 0:
                continue
            if num in s:
                return False;
            s.add(num)
        return max(s) - min(s) <= 4
posted @ 2018-08-30 14:29  一条图图犬  阅读(101)  评论(0编辑  收藏  举报