-
find numbers with even number of digits릿코드(LEETCODE) 2020. 2. 3. 16:55반응형
https://leetcode.com/problems/find-numbers-with-even-number-of-digits
주어진 숫자에의 자릿수가 짝수인지 판별하는 문제
class Solution { public: int getCnt(int cand) { int count = 0; while(cand) { cand /= 10; count++; } return count; } int findNumbers(vector<int>& nums) { const int size = nums.size(); int sol = 0; for(int i=0; i<size; i++) { int cand = getCnt(nums[i]); if(cand % 2 == 0) { sol++; } } return sol; } };
흠 또무엇인지 속도에 문제가 있나보다.
Runtime: 8 ms, faster than 74.81% of C++ online submissions for Find Numbers with Even Number of Digits.
Memory Usage: 8.9 MB, less than 100.00% of C++ online submissions for Find Numbers with Even Number of Digits.같은 소스를 다시 한번 제출해 보았다.
Runtime: 4 ms, faster than 98.44% of C++ online submissions for Find Numbers with Even Number of Digits.
Memory Usage: 9 MB, less than 100.00% of C++ online submissions for Find Numbers with Even Number of Digits.
-_- 채점기에 뭔가 오류가 있나보다..
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
1323. Maximum 69 Number (0) 2020.02.03 Split a String in Balanced Strings (0) 2020.02.03 subtract the product and sum of digits of an integer submissions (0) 2020.02.03 decompress run length encoded list (0) 2020.02.03 defanging-an-ip-address (0) 2020.02.03