Sangmun

283. Move Zeroes 본문

알고리즘/리트코드

283. Move Zeroes

상상2 2023. 5. 4. 11:06

https://leetcode.com/problems/move-zeroes/submissions/944108528/

 

Move Zeroes - LeetCode

Can you solve this real interview question? Move Zeroes - Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array.   E

leetcode.com

class Solution:
    def moveZeroes(self, nums: List[int]) -> None:

        l = 0
        for r in range(len(nums)):
            if nums[r]:
                nums[l], nums[r] = nums[r], nums[l]
                l += 1

'알고리즘 > 리트코드' 카테고리의 다른 글

459. Repeated Substring Pattern  (0) 2023.08.12
Palindrome  (0) 2023.04.27
516. Longest Palindromic Subsequence  (0) 2023.04.22
662. Maximum Width of Binary Tree  (0) 2023.04.20
Leet code Validate Stack Sequences  (0) 2023.04.13
Comments