leetcode- 168 field title race week - statistical median of an even number of digital

To give you an array of integers nums, you return to where the median of an even number of numbers.

Example 1:

输入:nums = [12,345,2,6,7896]
输出:2

Explanation: 2 is 12 digits (number of bits is an even number) 345 3 digits (digits is odd) is a 2 digit (odd digits) 1 6
digits is odd digits) 7896 is 4 digits (median of an even number) so only 12 and a median of 7896 is an even number of digital

Example 2:

输入:nums = [555,901,482,1771]
输出:1 

Explanation: Only 1771 was a median of numbers even.

prompt:

1 <= nums.length <= 500 1 <= nums[i] <= 10^5

/**
 * @param {number[]} nums
 * @return {number}
 */
var findNumbers = function(nums) {
    let count=0;
    for(let i=0;i<nums.length;i++){
        if(`${nums[i]}`.length%2==0){
            count++;
        }
    }
    return count;
};
Published 45 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_38407447/article/details/103741104