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. c#服务端图片打包下载

    一,设计多图片打包下载逻辑:1,如果是要拉取腾讯云等资源服务器的图片,2,我们先把远程图片拉取到本地的临时文件夹,3,然后压缩临时文件夹,4,压缩完删除临时文件夹,5,返回压缩完给用户,6,用户就去请 ...

  2. 微信小程序实现滑动删除效果

    在一些app中,随处可见左滑动的效果,在微信小程序中,官方并未提供相关组件,需要我们自己动手写一个类似的效果 下面仅列举出核心代码,具体的优化需要根据你自身的需求 <view class='li ...

  3. C# 从集合A中取出集合B中不包含的数据(根据ID判断),并添加到集合B中

    从一个集合A中取出另一个集合B中不包含的数据,并添加到集合B中 private void button2_Click(object sender, EventArgs e) { var ListA = ...

  4. 3-关于ES的几个小疑问和解答

    1.ES如何实现分布式 2.ES如何实现高实时 3.ES如何实现高扩展 4.ES7.x版本为何废弃type 5.搜索原理--知乎es

  5. js 学习三 Array

    1.数组的长度 var sequence = [1, 1, 2, 3, 5, 8, 13]; sequence .length //7 2.字符串转换成数组 string.split() var my ...

  6. vue.js(2)--v-cloak v-text v-html

    v-cloak v-text  v-html的使用 (1)实例 <!DOCTYPE html> <html lang="en"> <head> ...

  7. 记录-- vue+element树节点的标注

    html(背景:状态标注3钟颜色红黄绿对应0,1,2,) <el-tree @check="slclasscheck" v-if="treeShow" : ...

  8. 几个常用I/O函数用法(printf,fprintf等)

    一 格式化输出 1.printf 定义:int printf(const char *format,[argument]); 功能:产生格式化输出的函数(定义在 stdio.h 中) 参数说明:for ...

  9. ld - GNU linker (连接器)

    总览 (SYNOPSIS) ld [-o output] objfile... [-Aarchitecture] [-b input-format] [-Bstatic] [-Bdynamic] [- ...

  10. Source Insight 中调用Notepad++

    options>custom commands 指令为 "E:\Program Files (x86)\Notepad++\notepad++.exe" %f 其中%f表示S ...