Skip to content

Commit 2e60a28

Browse files
committed
Runtime: 62 ms (Top 15.48%) | Memory: 19.7 MB (Top 56.49%)
1 parent 676ec43 commit 2e60a28

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
// Runtime: 62 ms (Top 15.48%) | Memory: 19.7 MB (Top 56.49%)
12
class Solution {
23
public:
34
int findClosestNumber(vector<int>& nums) {
4-
// setting the ans to maximum value of int
5+
// setting the ans to maximum value of int
56
int ans = INT_MAX ;
6-
for(int i : nums){
7+
for(int i : nums){
78
// checking if each value of nums is less than the max value
89
if(abs(i) < abs(ans)){
9-
ans = i ; //check for the lesser value
10+
ans = i ; //check for the lesser value
1011
}
1112
else if(abs(i) == abs(ans)){
1213
ans = max (ans,i) ; // return the maximum in cases there are multiple answers
1314
}
1415
}
1516
return ans ;
1617
}
17-
};
18+
};

0 commit comments

Comments
 (0)