개발자도전
[LeetCode] Find Numbers with Even Number of Digits 본문
728x90
[문제]
Given an array nums of integers, return how many of them contain an even number of digits.
자리 수가 짝수인 개수 반환하기.
예 1.
Input: nums = [12,345,2,6,7896]
Output: 2
- 12와 7896만 2자리, 4자리 수로 짝수라서 2가 반환 됨.
예 2.
Input: nums = [555,901,482,1771]
Output: 1
- 1771만 4자리수로 짝수라 1이 반환됨.
[답]

nums에 있는 수들을 for문으로 빼서 숫자를 문자열로 바꿔주었다.
바꾼 문자열의 길이를 2로 나눴을 경우 나머지가 0이면 짝수라는 뜻이니까 이 때 count를 1 더해주도록 해주었다.
그리고 그 count값을 return 시켜주었다.
728x90
'LeetCode' 카테고리의 다른 글
| [LeetCode] Remove Element (0) | 2023.01.26 |
|---|---|
| [LeetCode] Merge Sorted Array (0) | 2023.01.25 |
| [LeetCode] Duplicate Zeros (0) | 2023.01.20 |
| [LeetCode] Squares of a Sorted Array (2) | 2023.01.19 |
| [LeetCode] Max Consecutive Ones (0) | 2023.01.19 |
Comments