标签:i++ solution begin code offer 之间 剑指offer turn 就是
把数与数之间的缝隙用0去填,如果0够用那么就是顺子;如果0用完了仍然填不完缝隙,那么就组不成顺子
class Solution {
public:
bool IsContinuous( vector<int> nums ) {
int size = nums.size();
if(size == 0)return false;
sort(nums.begin(),nums.end());
int zero_count = 0;
while(nums[zero_count]==0)
{
zero_count++;
}
for(int i=zero_count;i<size-1;i++)
{
if(nums[i]+1!=nums[i+1])
{
while(zero_count>0 && nums[i]+1!=nums[i+1])
{
zero_count--;
nums[i]++;
}
if(zero_count==0 && nums[i]+1!=nums[i+1])return false;
}
}
return true;
}
};
标签:i++ solution begin code offer 之间 剑指offer turn 就是
原文地址:https://www.cnblogs.com/virgildevil/p/12268479.html