Note the time complexity of str() convertion is O(len(S)) S: target string
class Solution:
def findNumbers(self, nums: List[int]) -> int:
"""tc O(N*max(len(str(num)))) sc O(1)
"""
res = 0
for x in nums:
res += 1 - len(str(x))%2
return res
Trick 2 : look at the value range
class Solution:
def findNumbers(self, nums: List[int]) -> int:
"""tc O(N) sc O(1)
"""
cnt = 0
for x in nums:
if (x > 9 and x <100) or (x > 999 and x <10000) or x == 10**5:
cnt += 1
return cnt