Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

개발자도전

[LeetCode] Duplicate Zeros 본문

LeetCode

[LeetCode] Duplicate Zeros

도do 2023. 1. 20. 11:02
728x90

[문제]

Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.

Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.

 

고정 길이 정수 배열 배열이 주어졌을 때, 나머지 요소들을 오른쪽으로 이동시키면서 0의 각 발생을 반복한다.

원래 배열의 길이를 초과하는 요소는 기록되지 않습니다. 위의 수정 작업을 제자리에 있는 입력 배열에 수행하고 아무것도 반환하지 마십시오.

배열 중 0이 있으면 그 후의 요소들은 오른쪽으로 이동시키고 0을 한 번 더 나오게 해주기.

 

예 1.

Input: arr = [1,0,2,3,0,4,5,0]
Output: [1,0,0,2,3,0,0,4]

 

예 2.

Input: arr = [1,2,3]
Output: [1,2,3]

  - arr에 0이 없어서 이동해줄필요 없이 arr값을 출력.

 

[답]

 

728x90

'LeetCode' 카테고리의 다른 글

[LeetCode] Remove Element  (0) 2023.01.26
[LeetCode] Merge Sorted Array  (0) 2023.01.25
[LeetCode] Squares of a Sorted Array  (2) 2023.01.19
[LeetCode] Find Numbers with Even Number of Digits  (1) 2023.01.19
[LeetCode] Max Consecutive Ones  (0) 2023.01.19
Comments