//GitHub https://github.com/vellimole0621
LeetCode - Find Numbers with Even Number of Digits
문제 설명
:
Given an array nums of integers, return how many of them contain an even number of digits.
=> 수로 이루어진 배열이 주어질 때, 자릿수가 짝수인 수를 얼마나 가지고 있는지를 반환하라.
내 풀이
:
각 수를 문자열로 바꿔서, 그 길이가 2로 나눠지는지로 자릿수가 짝수인지 아닌지를 판명 => 판명된 수의 개수를 모두 더해 반환
# Find Numbers with Even Number of Digits
# https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/
class Solution:
def findNumbers(self, nums: List[int]) -> int:
even_num = 0
for i in range(0, len(nums)):
check_num = str(nums[i])
if len(check_num) % 2 == 0:
even_num += 1
return even_num
'프로그래밍 > Python' 카테고리의 다른 글
[파이썬 Python/알고리즘] LeetCode - Duplicate Zeros (0) | 2023.09.05 |
---|---|
[파이썬 Python/알고리즘] LeetCode - Squares of a Sorted Array (0) | 2023.09.05 |
[파이썬 Python/알고리즘] LeetCode - Max Consecutive Ones (0) | 2023.08.28 |
[파이썬 Python/알고리즘] LeetCode - Ransom Note (0) | 2023.08.01 |
[파이썬 Python/알고리즘] LeetCode - Number of Steps to Reduce a Number to Zero (0) | 2023.07.31 |