Day19:给定一个整数数组nums,请你返回其中位数为偶数的数字的个数
eg:input : nums = [12,345,2,6,7896]
output : 2(其中12和7896是偶数位数)
1 def findNumbers(nums): 2 #方法一 3 num = [str(i) for i in nums] 4 count = 0 5 i = 0 6 while i < len(nums): 7 if len(num[i]) % 2 == 0: 8 count += 1 9 i += 1 10 return count 11 12 #方法二 13 #num = map(str,nums) 14 #count = 0 15 #for i in num: 16 #if len(i) % 2 == 0: 17 #count += 1 18 #return count 19 if __name__ == "__main__": 20 nums = [12,345,2,6,7896] 21 print(findNumbers(nums))
输出结果:2