Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- ChatGPT
- SW Expert Academy
- 맥북
- 금융문자분석경진대회
- Kaggle
- hackerrank
- 캐치카페
- ubuntu
- Docker
- 프로그래머스
- Baekjoon
- 코로나19
- dacon
- leetcode
- 편스토랑 우승상품
- 자연어처리
- 프로그래머스 파이썬
- AI 경진대회
- Real or Not? NLP with Disaster Tweets
- programmers
- 편스토랑
- 더현대서울 맛집
- 데이콘
- Git
- github
- PYTHON
- gs25
- 파이썬
- 우분투
- 백준
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1089. Duplicate Zeros (Python) 본문
728x90
반응형
Given a fixed length array arr of integers, 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, do not return anything from your function.
Example 1:
Input: [1,0,2,3,0,4,5,0]
Output: null
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
Example 2:
Input: [1,2,3]
Output: null
Explanation: After calling your function, the input array is modified to: [1,2,3]
Note:
- 1 <= arr.length <= 10000
- 0 <= arr[i] <= 9
Solution
class Solution:
def duplicateZeros(self, arr: List[int]) -> None:
"""
Do not return anything, modify arr in-place instead.
"""
answer_temp = []
for num in arr:
if num == 0:
answer_temp.append(num)
answer_temp.append(num)
answer = answer_temp[:len(arr)]
for i in range(len(arr)):
arr[i] = answer[i]
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 896. Monotonic Array (Python) (0) | 2020.10.09 |
---|---|
[leetCode] 258. Add Digits (Python) (0) | 2020.10.08 |
[leetCode] 17. Letter Combinations of a Phone Number (Python) (0) | 2020.10.06 |
[leetCode] 350. Intersection of Two Arrays II (Python) (0) | 2020.10.05 |
[leetCode] 729. My Calendar I (Python) (2) | 2020.10.04 |
Comments