an extremely easy q
class Solution:
def findNumbers(self, nums: List[int]) -> int:
ans = 0
for num in nums:
if len(str(num))%2==0:
ans+=1
return ans
actually there is a better logic
we know from 0~9 it is odd
10~99 is even
100~999 is odd
and so on and we can set the constraints like this
class Solution {
public int findNumbers(int[] nums) {
int count=0;
for(int i =0 ; i< nums.length; i++){
if((nums[i]>9 && nums[i]<100) || (nums[i]>999 && nums[i]<10000) || nums[i]==100000){
count++;
}
}
return count;
}
}
n time
1 space