leetcode Plus One
2015-12-11 20:08
405 查看
原题链接:https://leetcode.com/problems/plus-one/
The digits are stored such that the most significant digit is at the head of the list.
Description
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.
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ for i in reversed(range(len(digits))): if digits[i] == 9: digits[i] = 0 if i == 0: digits.insert(0, 1) else: digits[i] += 1 break return digits
相关文章推荐
- 求数列的和
- C++OJ提交题目中的语言选项里G++与C++的区别
- LVM是逻辑盘卷管理2
- Maven中的依赖传递与Maven中隐士变量的用法
- 错误:error LNK2005 解决方法
- 从这里开始——现实世界的理性视角
- 操作系统面试题总结
- 二叉树的下一个结点
- ACM迷宫问题java描述
- 【转】find命令
- 枚举+并查集 之 CODE[VS] 1001 舒适的路线 2006年
- URL传递中文解决方案
- 删除链表中重复的结点
- 线性代数基础知识-2
- 源码安装apache2.4
- std::decay
- 小猪的数据结构辅助教程——2.5 经典例子:约瑟夫问题的解决
- 十进制转二进制,八进制,十六进制
- easyui出口excel无法下载框弹出的办法来解决
- 求一个字符串中连续出现次数最多的子串