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 |
Tags
- Matrix
- Stack
- Counting
- two pointers
- dynamic programming
- Class
- sorting
- geometry
- hash table
- Number Theory
- 파이썬
- bit manipulation
- Binary Search
- 코딩테스트
- simulation
- Method
- implement
- Binary Tree
- string
- SQL
- database
- Tree
- java
- 구현
- 자바
- Math
- greedy
- Data Structure
- array
- 코테
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1389. Create Target Array in the Given Order 본문
1. Input
1) 정수 배열 nums
2) 정수 배열 index
2. Output
1) 다음 규칙에 따른 target 배열 반환
2) 규칙
- 초기 배열은 비어있다.
- target배열의 index[i]번째에 nums[i]를 추가한다.
- 더이상 읽을 nums[i]와 index[i]가 없을 때까지 반복한다.
3. Constraint
1) 1 <= nums.length, index.length <= 100
2) nums.length == index.length
3) 0 <= nums[i] <= 100
4) 0 <= index[i] <= i
5) 잘못된 연산은 나오지 않는다.
4. Example
Input: nums = [0,1,2,3,4], index = [0,1,2,2,1] -> Output: [0,4,1,3,2]
설명:
nums index target
0 0 [0] - 0을 0번째에
1 1 [0,1] - 1을 1번째에
2 2 [0,1,2] - 2를 2번째에
3 2 [0,1,3,2] - 3을 2번째에
4 1 [0,4,1,3,2] - 4를 1번째에
5. Code
1) 첫 코드(2022/06/12)
import java.util.*;
// target[index[i]] = nums[i];
List<Integer> list = new ArrayList();
for(int i=0 ; i<nums.length ; i++)
list.add(index[i], nums[i]);
int[] result = new int[nums.length];
for(int i=0 ; i<nums.length ; i++)
result[i] = list.get(i);
return result;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1408. String Matching in an Array (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1394. Find Lucky Integer in an Array (0) | 2022.12.24 |
[LeetCode/Easy] 1385. Find the Distance Value Between Two Arrays (0) | 2022.12.24 |
[LeetCode/Easy] 1365. How Many Numbers Are Smaller Than the Current Number (0) | 2022.12.24 |
[LeetCode/Easy] 1351. Count Negative Numbers in a Sorted Matrix (0) | 2022.12.24 |