文件: root - text - article - 2019 - 11 - moving-zeros.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 1056 次阅读, 17948 次搜索 | 103 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 1056 次阅读, 17948 次搜索 | 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 次阅读, 17948 次搜索 | 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: Longest Consecutive Sequence
- Progess made
- Daily Interview Problem: Reverse Integer
- Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
- [Daily Problem] Longest Palindromic Substring
- Algorithm Interview: String Compression
- Compare Version Numbers
- Daily Interview Problem: Reverse Words in a String
- Longest Substring Without Repeating Characters
- Daily Interview Problem: Spiral Traversal of Grid
©2006~2024 牛排过熟 - 0.00698 秒 - 2958.657 KB/s - 28 在线 内存: 493.76 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)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。