标签:ids cto 剑指offer amp iterator com types als --
没有判断数组长度,导致{1,3,2,5,4}输出结果是false是什么鬼???
------------------------------------------------------------------------
class Solution { public: bool IsContinuous( vector<int> numbers ) { if(numbers.size() > 5)return false; sort(numbers.begin(), numbers.end()); int zero = count(numbers.begin(), numbers.end(), 0);//0的个数 int len = unique(numbers.begin(),numbers.end())-numbers.begin();//去掉重复的长度 if(zero && len < 5-zero+1) return false;//存在非0重复 if(!zero && len < 5)return false; int minn; for(vector<int>::iterator it=numbers.begin(); it!=numbers.end(); it++) { if(*(it) == 0)continue; else if(minn ==0) { minn=*(it); } if(*(it) -minn+1 >5)return false; } return true; } };
标签:ids cto 剑指offer amp iterator com types als --
原文地址:https://www.cnblogs.com/evidd/p/10630171.html