标签:注意 begin tin bsp size 条件 false == nbsp
注意一个边界条件:必须是连续的,如果前后两个数是一样的也不满足条件
class Solution { public: bool IsContinuous( vector<int> numbers ) { int length = numbers.size(); if(length != 5) return false; sort(numbers.begin(),numbers.end()); int number = 0; for(int i = 0;i < length;i++){ if(numbers[i] == 0) number++; } int gap = 0; for(int i = number;i < length-1;i++){ if(numbers[i+1] - numbers[i] == 0) return false; gap += (numbers[i+1] - numbers[i] - 1); } if(gap > number) return false; else return true; } };
标签:注意 begin tin bsp size 条件 false == nbsp
原文地址:http://www.cnblogs.com/ymjyqsx/p/7513878.html