[leetcode]Plus One @ Python
原题地址:https://oj.leetcode.com/problems/plus-one/
题意:
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
解题思路:这只一个flag标志位就可以了。
代码:
class Solution:
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
flag =
for i in range(len(digits)-, -, -):
if digits[i] + flag == :
digits[i] =
flag =
else:
digits[i] = digits[i] + flag
flag = if flag == :
digits.insert(, )
return digits
[leetcode]Plus One @ Python的更多相关文章
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [LeetCode]题解(python):120 Triangle
题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...
- [LeetCode]题解(python):119 Pascal's Triangle II
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...
- [LeetCode]题解(python):118 Pascal's Triangle
题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...
- [LeetCode]题解(python):116 Populating Next Right Pointers in Each Node
题目来源 https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Given a binary tree ...
- [LeetCode]题解(python):114 Flatten Binary Tree to Linked List
题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...
- [LeetCode]题解(python):113 Path Sum II
题目来源 https://leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, find all root-to-leaf ...
- [LeetCode]题解(python):112 Path Sum
题目来源 https://leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if the tree ha ...
- [LeetCode]题解(python):111 Minimum Depth of Binary Tree
题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...
- [LeetCode]题解(python):110 Balanced Binary Tree
题目来源 https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is hei ...
随机推荐
- activiti初学
公司现有的工作流是比较老的JBPM,用起来不太方便,经常性的流程跑一半就停止不前了.闲暇之余学习下activiti的使用,基本配置如下: 1.创建pom.xml文件所依赖的jar包 <proje ...
- IEnumerable<T>
IEnumerable 饮水思源 <C#本质论> Overview 根据定义,.Net 的中集合,本质上是一个类,它最起码实现了IEnumeraable 或者非泛型的IEnumerable ...
- BZOJ.1013.[JSOI2008]球形空间产生器(高斯消元)
题目链接 HDU3571 //824kb 40ms //HDU3571弱化版 跟那个一比这个太水了,练模板吧. //列出$n+1$个二次方程后两两相减,就都是一次方程了. #include <c ...
- COGS NIOP联赛 图论相关算法总结
最小生成树 Kruskal+ufs int ufs(int x) { return f[x] == x ? x : f[x] = ufs(f[x]); } int Kruskal() { int w ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Cannot create a new pixel buffer adaptor with an asset writer input that has already started writing'
reason: '*** -[AVAssetWriterInputPixelBufferAdaptor initWithAssetWriterInput:sourcePixelBufferAttrib ...
- QtTest模块出现控制台的原因与方案
转到Qt安装目录下的mkspces/features目录下, 1.用记事本打开qtestlib.prf文件,注释掉CONFIG += console #CONFIG += console 2.用记事本 ...
- Mac安装jdk1.6
需到apple官网下载 下载地址:https://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US 相关介绍: http:// ...
- FireDAC 下的 Sqlite [9] - 关于排序
SQLite 内部是按二进制排序, 可以支持 ANSI; FrieDAC 通过 TFDSQLiteCollation 支持了 Unicode 排序, 并可通过其 OnCompare 事件自定义排序. ...
- 【教程】新手如何制作简单MAD和AMV,学不会那都是时辰
[教程]新手如何制作简单MAD和AMV,学不会那都是时 http://tieba.baidu.com/p/2303522172 [菜鸟教你做MAD]Vegas制作MAD入门教程 http://tieb ...