题目:2239. 找到最接近 0 的数字 - 力扣(LeetCode)
加班用手机刷水题,补个记录 +1
class Solution {
public:
int findClosestNumber(vector<int>& nums) {
int ret = nums[0];
for (int i = 1; i < nums.size(); i++) {
if (abs(nums[i]) == abs(ret) && ret < 0) ret = nums[i];
if (abs(nums[i]) < abs(ret)) ret = nums[i];
}
return ret;
}
};