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. Swoole开启守护进程后如何关闭

    查找相应端口号对应的PID(以我的为例,我的是9501端口) netstat -apn | 清除这个进程 启动客户端这时就会报错连不上了,证明服务已关

  2. 05.AutoMapper 之配置验证(Configuration Validation)

    https://www.jianshu.com/p/5901a5d1ef15 配置验证(Configuration Validation) 手写映射配置代码虽然繁琐,但具有可测试的优点.AutoMap ...

  3. Python的is和==区别

    字符串比较 1.比较字符串是否相同: ==:比较两个字符串内的value值是否相同 is:比较两个字符串的id值. 以上结果不同 比较数字时不能使用is,结果有时是True,有时是False,is 相 ...

  4. TS学习

    随着vue3.0的即将到来,是时候学习一下TS了 简介:TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类 ...

  5. wpf Textbox 回车就换行

    将 TextWrapping 属性设置为 Wrap 会导致输入的文本在到达 TextBox 控件的边缘时换至新行,必要时会自动扩展 TextBox 控件以便为新行留出空间. 将 AcceptsRetu ...

  6. inux下:热插拔和模块是什么

    一.何为模块? 文件系统.设备驱动程序.网络协议都可以理解为模块.模块本质也是普通的软件系统. 二.热插拔 硬件层面:只在不断电.不关闭系统的情况下增加或者删除对应部件,比如电源.硬盘.一些高端设备硬 ...

  7. java面试(Web相关)06

    1.JSP 和 servlet 有什么区别? JSP 是 servlet 技术的扩展,本质上就是 servlet 的简易方式.servlet 和 JSP 最主要的不同点在于,servlet 的应用逻辑 ...

  8. [易学易懂系列|rustlang语言|零基础|快速入门|(11)|Structs结构体]

    [易学易懂系列|rustlang语言|零基础|快速入门|(11)] 有意思的基础知识 Structs 我们今天来看看数据结构:structs. 简单来说,structs,就是用来封装相关数据的一种数据 ...

  9. React-Redux 总结

    一.定义与功能 React-Redux 将所有组件分成两大类:UI 组件(presentational component)和容器组件(container component) 1.UI 组件特征: ...

  10. LNMP 多版本PHP同时运行

    首先需要装好两个版本以上的PHP(例如:php5.6和php7两个版本).这里假设你已安装完成.1.配置并启动php默认版本: (设置 nginx 的 vhost 域名配置文件监听端口就好) 1).打 ...