1 class Solution { 2 public: 3 bool IsContinuous( vector<int> numbers ) { 4 if(numbers.size() != 5) 5 return 0; 6 map<int,int> mm; 7 for(int i = 0;i < 5 ; ++i) 8 { 9 if(mm.count(numbers[i]) == 0) 10 { 11 mm[numbers[i]] = 1; 12 } 13 else 14 { 15 ++mm[numbers[i]]; 16 } 17 } 18 int cnt = mm.count(0) > 0 ? mm[0] : 0; 19 int begin = cnt == 0 ? mm.begin()->first : ( ++ mm.begin() )->first; 20 for(int i = 0 ; i < 5 ;++i) 21 { 22 if (mm.count(begin) == 0) 23 { 24 --cnt; 25 if(cnt < 0) 26 { 27 return 0; 28 } 29 } 30 ++ begin; 31 } 32 return 1; 33 } 34 };
原文:http://www.cnblogs.com/xiaoyesoso/p/5161581.html