Given an array nums
of integers, return how many of them contain an even number of digits.
就是给一个数组,求数组里面每个数字的位数是偶数的个数。
对每个数不停除10得到每个数的位数,然后判断一下是否是偶数。
class Solution(object): def findNumbers(self, nums): """ :type nums: List[int] :rtype: int """ count = 0 for num in nums: digits = 0 while num > 0: num /= 10 digits += 1 if digits % 2 == 0: count += 1 return count