原题地址: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的更多相关文章

  1. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

  2. [LeetCode]题解(python):120 Triangle

    题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...

  3. [LeetCode]题解(python):119 Pascal's Triangle II

    题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...

  4. [LeetCode]题解(python):118 Pascal's Triangle

    题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...

  5. [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 ...

  6. [LeetCode]题解(python):114 Flatten Binary Tree to Linked List

    题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...

  7. [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 ...

  8. [LeetCode]题解(python):112 Path Sum

    题目来源 https://leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if the tree ha ...

  9. [LeetCode]题解(python):111 Minimum Depth of Binary Tree

    题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...

  10. [LeetCode]题解(python):110 Balanced Binary Tree

    题目来源 https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is hei ...

随机推荐

  1. Oracle中append与Nologging

    快速向表中插入大量数据Oracle中append与Nologging 2017-05-05 / VIEWS: 304 来源于:http://blog.sina.com.cn/s/blog_61cd89 ...

  2. 五校联考R1 Day2T2 矩阵matrix(容斥)

    题目链接 容易想到容斥,但是很恶心,因为要对行和列都容斥,然后行+列又要容斥.. 于是得到\(O(nm\log)\)的做法. 就有70分了: #include <cstdio> #incl ...

  3. git 撤销本地修改

    git checkout file 例如:git checkout app/views/carts/_index_m.html.erb 可以先用 git status 查看差异 然后 git chec ...

  4. windows servier2008+virtualenv下部署Flask (IIS+wfastcgi)

    由于业务只有一台windows server2008的服务器,一般的nginx+uwsgi的部署方式不行,以下记录部署过程,本文参考自:https://www.cnblogs.com/xiaolecn ...

  5. 【报错】RSA host key for 192.168.1.xxx has changed and you have requested strict checking.

    执行如下对机拷贝命令 scp .ssh/id_rsa.pub phpgo@192.168.1.35:~ 时,报错 RSA host key for 192.168.1.xxx has changed ...

  6. Javascript中的依赖注入

    首先通过带参函数来定义一个Javascript函数,相当于C#中的一个类. var Person = function(firstname, lastname){ this.firstname = f ...

  7. SpringUtils

    import org.springframework.beans.BeansException; import org.springframework.context.ApplicationConte ...

  8. Android App组件之Activity

    Android App组件之Activity 1 activit介绍 Activities 是Android的四大组件之一,其余三大组件是service.broadcast和content provi ...

  9. 关于电商ERP的想法

    原文地址: http://www.chinaodoo.net/thread-465-1-1.html 试用了下odoo的淘宝订单处理模块,从整个业务流程上已经打通,如果要求不是很高的话,现有的功能基本 ...

  10. VisualStudio: Vistual Studio XML 智能提示(转载)

    原文地址:http://blog.csdn.net/hispring/article/details/5332312. 开发中经常遇到要和各种各样的 XML 打交道,编辑 XML 文件时最头痛的便是要 ...