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
- SQL
- Binary Tree
- 구현
- Stack
- implement
- greedy
- geometry
- java
- simulation
- 자바
- Tree
- Counting
- 코딩테스트
- Class
- sorting
- dynamic programming
- Binary Search
- 코테
- Method
- Matrix
- string
- hash table
- database
- Data Structure
- 파이썬
- Number Theory
- Math
- array
- bit manipulation
- two pointers
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 배열의 원소만큼 추가하기 본문
1. Input, Output, Example
아무 원소도 들어있지 않은 빈 배열 X가 있다.
- arr의 앞에서부터 차례대로 원소를 보면서 원소가 a라면 X의 맨 뒤에 a를 a번 추가하는 일을 반복한 뒤의 배열 X를 반환
2. Constraint
1) 1 ≤ arr의 길이 ≤ 100
2) 1 ≤ arr의 원소 ≤ 100
3. Code
1) 첫 코드(2023/04/27)
import java.util.*;
class Solution {
public int[] solution(int[] arr) {
ArrayList<Integer> list = new ArrayList<>();
for(int i : arr){
for(int j=0 ; j<i ; j++)
list.add(i);
}
int[] answer = new int[list.size()];
for(int i=0 ; i<answer.length ; i++)
answer[i] = list.get(i);
return answer;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 왼쪽 오른쪽 (0) | 2023.04.27 |
---|---|
[프로그래머스/Lv.0] 간단한 식 계산하기 (0) | 2023.04.27 |
[프로그래머스/Lv.0] 접미사 배열 (0) | 2023.04.27 |
[프로그래머스/Lv.0] 뒤에서 5등까지 (0) | 2023.04.27 |
[프로그래머스/Lv.0] 배열의 길이에 따라 다른 연산하기 (0) | 2023.04.27 |