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
- geometry
- Binary Tree
- sorting
- dynamic programming
- Tree
- Binary Search
- Counting
- database
- string
- Math
- Number Theory
- two pointers
- 코딩테스트
- implement
- Stack
- greedy
- array
- Data Structure
- Method
- bit manipulation
- 파이썬
- SQL
- hash table
- 구현
- 코테
- java
- Class
- Matrix
- 자바
- simulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 홀수 vs 짝수 본문
1. Input, Output, Example
- 가장 첫 번째 원소를 1번 원소라고 할 때, 홀수 번째 원소들의 합과 짝수 번째 원소들의 합 중 크거나 같은 값을 반환
2. Constraint
1) 5 ≤ num_list의 길이 ≤ 50
2) -9 ≤ num_list의 원소 ≤ 9
3. Code
1) 첫 코드(2023/04/25)
class Solution {
public int solution(int[] num_list) {
int even = 0, odd = 0, a = 0, b = 1;
while(a<num_list.length || b<num_list.length){
if(a<num_list.length){
even += num_list[a];
a += 2;
}
if(b<num_list.length){
odd += num_list[b];
b += 2;
}
}
return Math.max(even, odd);
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 문자열 여러 번 뒤집기 (0) | 2023.04.25 |
---|---|
[프로그래머스/Lv.0] 배열 만들기 2 (0) | 2023.04.25 |
[프로그래머스/Lv.0] 배열의 원소 삭제하기 (0) | 2023.04.25 |
[프로그래머스/Lv.0] ad 제거하기 (0) | 2023.04.25 |
[프로그래머스/Lv.0] 할 일 목록 (0) | 2023.04.25 |