Skip to content

Commit 1ab0b3b

Browse files
committed
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 17.8 MB (83.23%)
1 parent 677372d commit 1ab0b3b

File tree

1 file changed

+15
-12
lines changed
  • 1421-find-numbers-with-even-number-of-digits

1 file changed

+15
-12
lines changed
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
class Solution(object):
2-
def findNumbers(self, nums):
3-
"""
4-
:type nums: List[int]
5-
:rtype: int
6-
"""
7-
count = 0
8-
1+
# Approach 2: Convert to String
2+
3+
# N = len(nums), M = max(nums)
4+
# Time: O(N * log M)
5+
# Space: O(log M)
6+
7+
class Solution:
8+
def findNumbers(self, nums: List[int]) -> int:
9+
result = 0
10+
911
for num in nums:
10-
if len(str(num)) % 2 == 0:
11-
count += 1
12-
13-
return count
12+
len_ = len(str(num))
13+
if len_ % 2 == 0:
14+
result += 1
15+
16+
return result
1417

0 commit comments

Comments
 (0)