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
- Data Structure
- 파이썬
- two pointers
- sorting
- 구현
- 코테
- Binary Search
- 자바
- Tree
- string
- Number Theory
- Stack
- simulation
- implement
- Method
- geometry
- array
- Math
- Class
- 코딩테스트
- database
- java
- Counting
- Binary Tree
- greedy
- hash table
- dynamic programming
- SQL
- bit manipulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 배열의 길이에 따라 다른 연산하기 본문
1. Input, Output, Example
- arr의 길이가 홀수라면 arr의 모든 짝수 인덱스 위치에 n을 더한 배열을, arr의 길이가 짝수라면 arr의 모든 홀수 인덱스 위치에 n을 더한 배열을 반환
2. Constraint
1) 1 ≤ arr의 길이 ≤ 1,000
2) 1 ≤ arr의 원소 ≤ 1,000
3) 1 ≤ n ≤ 1,000
3. Code
1) 첫 코드(2023/04/27)
class Solution {
public int[] solution(int[] arr, int n) {
if(arr.length%2==0){
for(int i=1 ; i<arr.length ; i+=2)
arr[i] += n;
} else{
for(int i=0 ; i<arr.length ; i+=2)
arr[i] += n;
}
return arr;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 접미사 배열 (0) | 2023.04.27 |
---|---|
[프로그래머스/Lv.0] 뒤에서 5등까지 (0) | 2023.04.27 |
[LeetCode/Easy] 2032. Two Out of Three (0) | 2023.04.27 |
[LeetCode/Easy] 2094. Finding 3-Digit Even Numbers (0) | 2023.04.26 |
[LeetCode/Easy] 2078. Two Furthest Houses With Different Colors (0) | 2023.04.26 |