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
- Matrix
- two pointers
- 자바
- Math
- Binary Tree
- bit manipulation
- Number Theory
- 코테
- 파이썬
- SQL
- Counting
- array
- implement
- Method
- greedy
- Class
- Tree
- simulation
- java
- hash table
- Binary Search
- string
- Stack
- 코딩테스트
- sorting
- database
- geometry
- 구현
- dynamic programming
- Data Structure
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1295. Find Numbers with Even Number of Digits 본문
1. Input
1) 정수 배열 nums
2. Output
1) nums의 요소 중 짝수개의 숫자로 이루어진 요소의 개수
3. Constraint
1) 1 <= nums.length <= 500
2) 1 <= nums[i] <= 10^5
4. Example
Input: nums = [12,345,2,6,7896] -> Output: 2
설명:
- 12는 2개의 숫자로 이루어져 있음(O)
- 345는 3개의 숫자로 이루어져 있음(X)
- 2는 1개의 숫자로 이루어져 있음(X)
- 6은 1개의 숫자로 이루어져 있음(X)
- 7896은 4개의 숫자로 이루어져 있음(O)
- 따라서 2를 반환한다.
5. Code
1) 첫 코드(2022/06/15)
int count = 0;
for(int i=0 ; i<nums.length ; i++)
if((int)(Math.log10(nums[i]))%2==1)
count++;
return count;
2) 수정해본 코드(2022/12/24)
int answer = 0;
for(int n : nums){
if(String.valueOf(n).length()%2==0)
answer++;
}
return answer;
- 1번 코드와 속도는 비슷하나 공간절약이 더 많이 됐다.