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
- 코로나19
- 캐치카페
- Git
- gs25
- leetcode
- 맥북
- 데이콘
- ChatGPT
- 프로그래머스
- Docker
- 파이썬
- programmers
- 백준
- 편스토랑 우승상품
- github
- AI 경진대회
- 자연어처리
- Real or Not? NLP with Disaster Tweets
- 우분투
- hackerrank
- 편스토랑
- Kaggle
- PYTHON
- 프로그래머스 파이썬
- dacon
- SW Expert Academy
- Baekjoon
- 더현대서울 맛집
- 금융문자분석경진대회
- ubuntu
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 283. Move Zeroes (Python) 본문
728x90
반응형

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Example:
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
Note:
- You must do this in-place without making a copy of the array.
- Minimize the total number of operations.
Solution
class Solution:
def moveZeroes(self, nums):
for i in range(len(nums))[::-1]:
if nums[i] == 0:
nums.pop(i)
nums.append(0)



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[HackerRank] Sorting: Comparator (Python) (0) | 2020.06.20 |
---|---|
[leetCode] 633. Sum of Square Numbers (Python) (0) | 2020.06.19 |
[leetCode] 20. Valid Parentheses (Python) (0) | 2020.06.17 |
[leetCode] 125. Valid Palindrome (Python) (0) | 2020.06.16 |
[leetCode] 387. First Unique Character in a String (Python) (0) | 2020.06.15 |