题解 | 缺失数字
缺失数字
http://www.nowcoder.com/practice/9ce534c8132b4e189fd3130519420cde
class Solution { public: int solve(vector& a) { int len = a.size(); for(int i = 0; i < len; i++) { if(i == 0 && a[i] != 0) { return 0; } else if(i == len - 1 && a[i] != len) { return len; } else if(a[i + 1] != a[i] + 1) { return a[i] + 1; } } return 0; } };