반응형
숫자들 중에 짝수 자릿수인 숫자의 개수를 반환하는 문제.
고대로 해주면 된다.
class Solution {
public:
int findNumbers(vector<int>& nums) {
int ans = 0;
int sth =0;
for(int i = 0; i<nums.size(); i++){
sth = 0;
while(nums[i]){
nums[i] /=10;
sth++;
}
if(sth %2==0)
ans++;
}
return ans;
}
};
반응형
'IT > 알고리즘' 카테고리의 다른 글
13] Leetcode 709. To Lower Case (0) | 2020.06.25 |
---|---|
12] Leetcode 1486. XOR Operation in an Array (0) | 2020.06.24 |
10] Leetcode 1389. Create Target Array in the Given Order (0) | 2020.06.23 |
9] Leetcode 1281. Subtract the Product and Sum of Digits of an Integer (0) | 2020.06.22 |
8] Leetcode 1313. Decompress Run-Length Encoded List (0) | 2020.06.21 |
댓글