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
- hash table
- Number Theory
- 자바
- string
- 코테
- 코딩테스트
- Matrix
- java
- 구현
- 파이썬
- Math
- Tree
- array
- Method
- greedy
- Data Structure
- Class
- database
- sorting
- Counting
- dynamic programming
- implement
- simulation
- SQL
- Binary Tree
- geometry
- two pointers
- Binary Search
- bit manipulation
- Stack
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 짝수의 합 본문
1. Input
1) 정수 n
2. Output
2) n 이하의 짝수를 모두 더한 값
3. Constraint
1) 0 < n <= 1000
4. Example
Input: n=10 -> Output: 30
설명: 2 + 4 + 6 + 8 + 10 = 30
5. Code
1) 첫 코드(2022/10/17)
int answer = 0;
n = n%2==0 ? n : n-1;
for(int i=n ; i>0 ; i-=2)
answer += i;
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 외계행성의 나이 (0) | 2022.10.21 |
---|---|
[프로그래머스/Lv.0] 배열 자르기 (0) | 2022.10.21 |
[프로그래머스/Lv.0] 양꼬치 (0) | 2022.10.21 |
[프로그래머스/Lv.0] 각도기 (0) | 2022.10.21 |
[프로그래머스/Lv.0] 특정 문자 제거하기 (0) | 2022.10.21 |