Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.
&nbsp;
Example 1:

Input: nums = [-4,-2,1,4,8]
Output: 1
Explanation:
The distance from -4 to 0 is |-4| = 4.
The distance from -2 to 0 is |-2| = 2.
The distance from 1 to 0 is |1| = 1.
The distance from 4 to 0 is |4| = 4.
The distance from 8 to 0 is |8| = 8.
Thus, the closest number to 0 in the array is 1.


Example 2:

Input: nums = [2,-1,1]
Output: 1
Explanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.


&nbsp;
Constraints:


	1 &lt;= n &lt;= 1000
	-105 &lt;= nums[i] &lt;= 105


class Solution:
    
    def findClosestNumber1(self, nums: List[int]) -> int:
        return min(nums, key=lambda x: (abs(x), -x))
    
    def findClosestNumber2(self, nums: List[int]) -> int:
        return min(nums, key=lambda x: abs(x - .1))
    
    def findClosestNumber3(self, nums: List[int]) -> int:
        return max((-abs(x), x) for x in nums)[1]
    
    def findClosestNumber4(self, nums: List[int]) -> int:
        return -min(zip(map(abs, nums), map(neg, nums)))[1]

    def findClosestNumber5(self, nums: List[int]) -> int:
        a = min(map(abs, nums))
        return a if a in nums else -a

    def findClosestNumber6(self, nums: List[int]) -> int:
        a = abs(min(nums, key=abs))
        return a if a in nums else -a

    def findClosestNumber7(self, nums: List[int]) -> int:
        x = min(nums, key=abs)
        return x if x >= 0 or -x not in nums else -x
    
    def findClosestNumber8(self, nums: List[int]) -> int:
        return min(sorted(nums, reverse=True), key=abs)
    
    def findClosestNumber9(self, nums: List[int]) -> int:        
        a = abs(nums[0])
        for x in nums:
            if x < 0:
                x = -x
            if x < a:
                a = x
        return a if a in nums else -a
        
    def findClosestNumberA(self, nums: List[int]) -> int:        
        pos = 999999
        neg = -pos
        for x in nums:
            if x < 0:
                if x > neg:
                    neg = x
            elif x < pos:
                pos = x
        return pos if pos <= -neg else neg
        
    def findClosestNumberB(self, nums: List[int]) -> int:        
        pos = 999999
        neg = -pos
        for x in nums:
            if x < pos and neg < x:
                if x < 0:
                    neg = x
                else:
                    pos = x
        return pos if pos <= -neg else neg
        
    def findClosestNumberC(self, nums: List[int]) -> int:        
        pos = 999999
        neg = -pos
        for x in nums:
            if neg < x and x < pos:
                if x < 0:
                    neg = x
                else:
                    pos = x
        return pos if pos <= -neg else neg
        
    def findClosestNumberD(self, nums: List[int]) -> int:        
        pos = 999999
        neg = -pos
        for x in nums:
            if neg < x < pos:
                if x < 0:
                    neg = x
                else:
                    pos = x
        return pos if pos <= -neg else neg
        
    def findClosestNumber(self, nums: List[int], timess=defaultdict(lambda: [0] * 10), testcase=[0]) -> int:
        name = 'findClosestNumber'
        solutions = [getattr(self, s)
                     for s in dir(self)
                     if s.startswith(name)
                     and s != name]
        expect = dummy = object()
        from time import perf_counter as time
        for i in range(10):
            shuffle(solutions)
            for solution in solutions:
                start = time()
                result = solution(nums)
                end = time()
                if expect is dummy:
                    expect = result
                assert result == expect
                timess[solution.__name__][i] += end - start
        testcase[0] += 1
        if testcase[0] == 224:
            for name, times in sorted(timess.items(), key=lambda nt: sorted(nt[1])):
                print(name, *(f'{t*1e3:6.2f} ms' for t in sorted(times)[:3]))
            return
        return result
		
// If absolute of n is less than min, update the closest_num 
// If absolute of n is same of as min, update the bigger closest_num

class Solution {
    public int findClosestNumber(int[] nums) {
        int min = Integer.MAX_VALUE, closest_num = 0;
        for(int n : nums) {
            if(min > Math.abs(n)) {
                min = Math.abs(n);
                closest_num = n;
            } else if(min == Math.abs(n) && closest_num < n) {
                closest_num = n;
            }
        }
        return closest_num;
    }
}
class Solution {
public:
    int findClosestNumber(vector<int>& nums) {
// setting the ans to maximum value of int
        int ans = INT_MAX ;
        for(int i : nums){
        // checking if each value of nums is less than the max value
            if(abs(i) < abs(ans)){
                ans = i ; //check for the lesser value
            }
            else if(abs(i) == abs(ans)){
                ans = max (ans,i) ; // return the maximum in cases there are multiple answers
            }
        }
        return ans ;
    }
};
//Solution 1
var findClosestNumber = function(nums) {
    
    let pos = Infinity;
    let neg = -Infinity;
    
    for(let i = 0; i < nums.length; i++) {
        
        if( nums[i] > 0 ){
           if( pos > nums[i] ) 
               pos = nums[i];               
        } else {
            if( neg < nums[i] )
                neg = nums[i];
        } 
    }
    
    if( -neg < pos ) {
       return neg;
    }
    
    return pos;   
};

//Solution 2
var findClosestNumber = function(nums) {
    
    let result = nums[0];
    
    for(let i=1; i<nums.length; i++) {
        
        let mod = Math.abs(nums[i]);
        
        if( Math.abs(result)>mod ) {            
            result = nums[i]
        }
        
        if( Math.abs(result) == mod ) {
            if( result<nums[i] ) {
                result = nums[i];
            }
        }
    }
    
    return result;    
};
Find Closest Number to Zero