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 |
Tags
- 더현대서울 맛집
- ChatGPT
- github
- hackerrank
- AI 경진대회
- Real or Not? NLP with Disaster Tweets
- Git
- 편스토랑 우승상품
- 우분투
- 캐치카페
- gs25
- 맥북
- Kaggle
- Docker
- 파이썬
- Baekjoon
- dacon
- 코로나19
- 자연어처리
- 데이콘
- leetcode
- SW Expert Academy
- 프로그래머스 파이썬
- ubuntu
- 금융문자분석경진대회
- programmers
- 백준
- 편스토랑
- PYTHON
- 프로그래머스
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