[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 ...
随机推荐
- Web大前端面试题-Day1
1. var的变量提升的底层原理是什么? JS引擎的工作方式是:1) 先解析代码,获取所有被声明的变量:2)然后在运行.也就是说分为预处理和执行两个阶段. 变量提升:所有变量的声明语句都会被提升到代码 ...
- Android Data Binding
Android官方数据绑定框架DataBinding, 1.什么是DataBinding 2.DataBinding基础用法 3.DataBinding原理 4.表达式 5.null检查 6.incl ...
- 使用 IntraWeb (3) - 页面切换
新建 StandAlone Application 工程后, 再通过 File > New > Other.. > IntraWeb > New Form 添加两个窗体. 然后 ...
- CentOS以守护进程的方式启动程序的另类用法daemon
在Linux下如果以守护进程的方式启动程序,也就是后台运行,有几种方式,比如后面带&&,nuhop,那么在CentOS下可以使用daemon这个函数来启动,比如: daemon --p ...
- UIScrollView 遇到的小坑
在做一个 UIScrollView 展示的时候 ,须要计算 contentSize 的高度,于是 我遍历了一下 UIScrollView 全部的子view的高度累加 然后得出 高度 .奇怪的是 发现 ...
- MCU PWM DAC OP Voltage Output
- Delphi 实现对注册表的监视和扫描
;iRes := RegEnumKey( hKeyx, dwIndex, buf, dwSize );if iRes = ERROR_NO_MORE_ITEMS thenbreakelse if iR ...
- lufylegend:图形变形1
HTML5中的几种变形 HTML5中的变形,共有以下几种方法 scale() 缩放 rotate() 旋转 translate() 平移 transform() 矩阵变形 setTransform() ...
- rawbytestring
rawbytestring Delphi 定义了 RawByteStrng 类型的字符串,定义如下: RawByteString = type AnsiString($ffff); 关于RawByte ...
- Unity3D 的大场景内存优化
我们公司的一个 MMORPG 项目最近在内存方面碰到了红线,昨天开会讨论了一下.我提出了一个改进方案,写篇 blog 记录一下. 问题是这样的.在当下的手机及平板硬件设备条件下,操作系统留给应用的可用 ...