题解 | #没有出现的编号#
没有出现的编号
https://www.nowcoder.com/practice/875d705df65c401a905f574070e09320
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型vector */ vector<int> findMissingAndMaxNegative(vector<int>& nums) { // write code here vector<int> posNUm; vector<int> negNum; for(auto &it : nums) { if (it <= 0) { negNum.push_back(it); } else if (it > 0) { posNUm.push_back(it); } } sort(posNUm.begin(),posNUm.end()); sort(negNum.begin(),negNum.end()); vector<int> result; if (posNUm.size() == 0) { result.push_back(1); } else { for (int i = 1;i <= posNUm.size();++i) { if (i != posNUm[i - 1]) { result.push_back(i); break; } } } if (result.size() == 0) { result.push_back(posNUm[posNUm.size() - 1] + 1); } if (negNum.size() != 0) { if (negNum[negNum.size() - 1] == 0) { result.push_back(negNum[negNum.size() - 2]); } else { result.push_back(negNum[negNum.size() - 1]); } } else { result.push_back(0); } return result; } };