文件: root - text - article - 2019 - 11 - moving-zeros.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 1056 次阅读, 17986 次搜索 | 103 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 1056 次阅读, 17986 次搜索 | 103 个单词
| 浏览 | 博客存档
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:
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 1056 次阅读, 17986 次搜索 | 103 个单词 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]
猜您喜欢...
- Algorithm Interview Question: H-Index
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
- Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
- Plus One
- Detect Linked List Cycle
- [Daily Problem] Validate Balanced Parentheses
- Daily Interview Problem: Longest Substring With K Distinct Characters
- Find Missing Numbers in an Array
©2006~2024 牛排过熟 - 0.00709 秒 - 7669.058 KB/s - 37 在线 内存: 515.96 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
牛排怎么做才好吃? | <meta name="机器人" content="不索引, 跟踪" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
评论 (0)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。