Python3解leetcode Binary Tree PathsAdd DigitsMove Zeroes
问题描述:
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.
思路:
主要是list的sort()函数的应用
代码:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
nums.sort(key = lambda x: x ==0)
key是sort()函数中的一个参数,该参数指定排序的元素。当前代码中排序元素就是nums中所有0元素,到最后所有0元素一组(新),除去0元素的其他元素一组(老),最终默认按照老-新的顺序将nums重新排序
Python3解leetcode Binary Tree PathsAdd DigitsMove Zeroes的更多相关文章
- Python3解leetcode Binary Tree PathsAdd Digits
问题描述: Given a non-negative integer num, repeatedly add all its digits until the result has only one ...
- Python3解leetcode Binary Tree Paths
问题描述: Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. E ...
- Python3解leetcode Same Tree
问题描述: Given two binary trees, write a function to check if they are the same or not. Two binary tree ...
- Python3解leetcode Symmetric Tree
问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- Python3解leetcode N-ary Tree Level Order Traversal
问题描述: Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to ...
- LeetCode:Binary Tree Level Order Traversal I II
LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...
- LeetCode: Binary Tree Traversal
LeetCode: Binary Tree Traversal 题目:树的先序和后序. 后序地址:https://oj.leetcode.com/problems/binary-tree-postor ...
- Python3解leetcode Average of Levels in Binary Tree
问题描述: Given a non-empty binary tree, return the average value of the nodes on each level in the form ...
- Python3解leetcode Lowest Common Ancestor of a Binary Search Tree
问题描述: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in ...
随机推荐
- 631D Messenger
题目大意 给你串s和t 但是每个串都被表示为多个二元组(x,y)表示字符x连续出现y次 问t在s中出现了多少次 分析 我们先将s和t每个串中二元组合并 即相邻两个二元组如果字符相等则将它们变为一个 特 ...
- IAR MSP430怎么破解?IAR for MSP430安装注册破解激活图文详细教程
IAR for MSP430全称IAR Embedded Workbench for MSP430,是一款功能强大的专业集成开发环境,软件包括项目管理.配置开发环境.创建编译器.定制具体编程方案等 ...
- HDU 2512 一卡通大冒险 (第二类斯特林数)
题目链接:HDU 2512 Problem Description 因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身.某天,他们在机房商量一个绝妙的计划 ...
- 题解[SCOI2009]粉刷匠 难度:省选/NOI-
Description windy有 N 条木板需要被粉刷.每条木板被分为 M 个格子.每个格子要被刷成红色或蓝色.windy每次粉刷,只能选择一条木板上一段连续的格子,然后涂上一种颜色.每个格子最多 ...
- Android深度探索-卷1第七章心得体会
创建LED驱动的设备文件 第一步:使用cdev_init函数初始化cdev 第二步:指定设备号.直接在代码指定或动态分配 第三步:使用cdev_add函数将字符设备添加到内核中的字符设备数组中 第四步 ...
- Yaconf – 一个高性能的配置管理扩展
鸟哥出品:http://www.laruence.com/2015/06/12/3051.html 首先说说, 这个是干啥的. 我见过很多的项目中, 用PHP文件做配置的, 一个config目录下可能 ...
- "CoolShell puzzle game" writeup
地址:http://fun.coolshell.cn/ Fuck your brain 看到一大串符号,还以为是 js 代码,结果放到 Chrome 控制台执行没有任何结果,然后搜了一下发现有一门叫B ...
- NGUI的窗体的推动和调节大小(drag object和drag resize object)
一,我们先添加一个sprite,给sprite添加一个背景图片,然后attach添加一个box Collider,但是这时我们右键attach是找不到drag object的我们需要在add comp ...
- 图解git中的最常用命令
图解git中的最常用命令 Git命令参考手册(文本版) git init # 初始化本地git仓库(创 ...
- 攻防世界--no-strings-attached
测试文件:https://adworld.xctf.org.cn/media/task/attachments/5d4117b968684b9483d0d4464e0a6fea 这道题要使用到gdb文 ...