mycode

主要在计算商和余数的时候一定要用还没更新的商和余数哦

class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
add = 1
for i in range(len(digits)-1,-1,-1):
digits[i],add= (digits[i] + add) % 10,(digits[i] + add) // 10
if add :
digits.insert(0,add)
return digits

参考:

def plusOne(self, digits):
j = len(digits) - 1
cout = 1
while(j >= 0 and cout):
digits[j] += cout
cout, digits[j] = digits[j] // 10, digits[j] % 10
j -= 1
return digits if not cout else [cout] + digits

leetcode-easy-array-66 .plus one的更多相关文章

  1. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  2. JS数组 谁是团里成员(数组赋值)var myarray = new Array(66,80,90,77,59);//创建数组同时赋值

    谁是团里成员(数组赋值) 数组创建好,接下来我们为数组赋值.我们把数组看似旅游团的大巴车,大巴车里有很多位置,每个位置都有一个号码,顾客要坐在哪个位置呢? 第一步:组个大巴车 第二步:按票对号入座 大 ...

  3. C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array

    26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...

  4. [LeetCode] Rotate Array 旋转数组

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  5. LeetCode(Easy)--C++笔记

    前言:这是关于LeetCode上面练习题C++的笔记,有些地方参考有网友的解题方法(可能有些参考没能注明,望谅解),如有需要改进的地方希望留言指教,多谢! 目录: ZigZag Conversion ...

  6. 2016.5.16——leetcode:Rotate Array,Factorial Trailing Zeroe

    Rotate Array 本题目收获: 题目: Rotate an array of n elements to the right by k steps. For example, with n = ...

  7. leetcode easy problem set

     *勿以浮沙筑高台* 持续更新........     题目网址:https://leetcode.com/problemset/all/?difficulty=Easy 1. Two Sum [4m ...

  8. 【LeetCode算法-58/66】Length of Last Word/Plus One

    LeetCode第58题: Given a string s consists of upper/lower-case alphabets and empty space characters ' ' ...

  9. LeetCode练题——66. Plus one

    1.题目 66. Plus One——easy Given a non-empty array of digits representing a non-negative integer, plus ...

  10. 决战Leetcode: easy part(51-96)

    本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! em ...

随机推荐

  1. 17.AutoMapper 之配置(Configuration)

    https://www.jianshu.com/p/031ff68797dd 配置(Configuration) 通过构造函数创建并初始化MapperConfiguration实例: config = ...

  2. redis常见问题和解决方案

    转载:https://www.cnblogs.com/aspirant/p/6820262.html [原创]那些年用过的Redis集群架构(含面试解析) redis常见问题和解决方案 持久化.主从问 ...

  3. Apache ab测试工具使用方法(无参、get传参、post传参)(转)

    转自Apache ab测试工具使用方法(无参.get传参.post传参) Ab测试工具是apache自带的测试工具,具有简单易上手的特性,下面我总结一下我的使用方法,首先去官方下载apache程序包, ...

  4. fork树

    i son/pa ppid pid fpid parent parent parent child child parent child parent parent child child child ...

  5. Linux20期学习笔记 Day2

    Linux系统进程状态及部分基础命令

  6. 007-SaltStack之修改salt-minion id

    1. 需求背景 之前使用saltstack添加的主机默认使用了hostname作为salt-minion id,而主机名如果没有做规范和规划,是比较难区分属于什么业务或者机器的.我们需要修改salt- ...

  7. PAT Basic 1066 图像过滤 (15 分)

    图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一行给出一幅图像的分辨 ...

  8. PHP判断邮箱地址是否合法的正则表达式

    PHP判断邮箱地址是否合法的正则表达式: function checkEmail($inAddress){ return (preg_match("/^([a-zA-Z0-9_-])+@([ ...

  9. Linux下vim显示行数

    在Linux环境下的编辑器有vi.vim.gedit等等.进入这些编辑器之后,为了方便我们需要编辑器显示出当前的行号,可偏偏编辑器默认是不会显示行号的.我们有二种办法可以解决: 第一种是,手动显示:在 ...

  10. 【SaltStack官方版】—— MANAGING THE JOB CACHE

    MANAGING THE JOB CACHE The Salt Master maintains a job cache of all job executions which can be quer ...