250x250
반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 개발자취업
- 인덕원역맛집
- 강남역맛집
- 코테사이트
- 개발자알고리즘
- 내돈내산
- 코딩테스트사이트추천
- 인덕원맛집
- 애플릿코드
- 인덕원존맛
- 알고리즘
- 인덕원카페
- 삼성맛집
- 아마존릿코드
- 코딩테스트
- 구글릿코드
- 프로그래머스
- 알고리즘해시
- 코딩테스트사이트
- 안양맛집
- 제주맛집
- 평촌카페
- 인덕원고기집
- 안양고기
- 제주볼거리
- 인덕원고기
- 제주놀거리
- 프로그래머스코딩테스트
- 릿코드
- 삼성역맛집
Archives
- Today
- Total
민여위-
[Leetcode] Find Numbers with Even Number of Digits (Explore Arrays 101) / 릿코드 활용, 코딩테스트 본문
Tech
[Leetcode] Find Numbers with Even Number of Digits (Explore Arrays 101) / 릿코드 활용, 코딩테스트
꿀땡이 2021. 10. 9. 22:08728x90
반응형
1. 문제설명
Given an array nums of integers, return how many of them contain an even number of digits.
Example 1:
Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits). Therefore only 12 and 7896 contain an even number of digits.
Example 2:
Input: nums = [555,901,482,1771] Output: 1 Explanation: Only 1771 contains an even number of digits.
Constraints:
- 1 <= nums.length <= 500
- 1 <= nums[i] <= 10^5
2. 내 풀이
class Solution {
public:
int findNumbers(vector<int>& nums) {
int nCountWords = 0;
for(int i = 0; i < nums.size(); i++) {
int nCountNumDigit = 0;
int nFlag = 1;
int tempData = nums[i];
while(nFlag) {
if(0 != tempData) {
nCountNumDigit ++;
tempData /= 10;
} else {
nFlag = 0;
}
}
if(0 == nCountNumDigit % 2) {
nCountWords ++;
}
}
return nCountWords;
}
};
728x90
반응형
'Tech' 카테고리의 다른 글
[Leetcode] Duplicate Zeros (Explore Arrays 101) / 릿코드 활용, 코딩테스트 (0) | 2021.10.09 |
---|---|
[Leetcode] Squares of a Sorted Array (Explore Arrays 101) / 릿코드 활용, 코딩테스트 (0) | 2021.10.09 |
[Leetcode] Max Consecutive Ones Solution (Explore Arrays 101) / 릿코드 활용, 코딩테스트 (0) | 2021.10.09 |
[알고리즘] 코딩테스트 사전 준비 (c++ 기준) (0) | 2021.10.01 |
[프로그래머스] 기능 개발 (스택/큐, 코딩테스트) (0) | 2021.10.01 |
Comments