class Solution { public: bool IsContinuous( vector<int> numbers ) { if (numbers.size() == 0) return false; sort(numbers.begin(), numbers.end()); int zeroCnt = 0; //0的个数 int index = 0; //第一个非0数字 while (numbers[index] == 0) { index++; zeroCnt++; } int sumDiff = 0; for (; index < numbers.size()-1; index++) { int diff = numbers[index + 1] - numbers[index]-1; if (diff == -1 ) { return false; //有对子 } sumDiff += diff; if (sumDiff > zeroCnt) { return false; } } return true; } };
原文:http://www.cnblogs.com/xiuxiu55/p/6642492.html