File: root - text - article - 2019 - 11 - moving-zeros.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1075 Views, 19273 Search Bots | 103 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1075 Views, 19273 Search Bots | 103 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Facebook:
By the way, check out our NEW project AlgoPro (http://algopro.com) for over 60+ video coding sessions with ex-Google/ex-Facebook engineers.
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]
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
Here is a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 1075 Views, 19273 Search Bots | 103 Words By the way, check out our NEW project AlgoPro (http://algopro.com) for over 60+ video coding sessions with ex-Google/ex-Facebook engineers.
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]
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
Here is a starting point:
class Solution:
def moveZeros(self, nums):
# Fill this in.
nums = [0, 0, 0, 2, 0, 1, 3, 4, 0, 0]
Solution().moveZeros(nums)
print(nums)
# [2, 1, 3, 4, 0, 0, 0, 0, 0, 0]
Related Articles
- Daily Interview Problem: Arithmetic Binary Tree
- Daily Interview Problem: Look and Say Sequence
- Daily Interview Problem: Largest Product of 3 Elements I
- Fibonacci coding
- [Daily Problem] Angles of a Clock
- Batch Programming in XP
- Plus One
- Absolute Path
- PHP Unit Tests on VPS Server
- Daily Interview Problem: Merge Overlapping Intervals
©2006~2024 SteakOverCooked - 0.0064 Seconds(s) - 3006.017 KB/s - 14 Online Memory: 497.3 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !