public class Solution {
public int[] PlusOne(int[] digits) {
var last = digits[digits.Length - ]; if (last + < )
{
digits[digits.Length - ]++;
return digits;
}
else
{
var list = new List<int>();
int step = ;
for (int i = digits.Length - ; i >= ; i--)
{
var cur = digits[i];
cur = cur + step;
if (cur >= )
{
step = ;
}
else
{
step = ;
} list.Add(cur % );//原来肯定是9,9+1变为10
} if (step == )
{
list.Add();
}
list.Reverse();
return list.ToArray();
}
}
}

https://leetcode.com/problems/plus-one/#/description

补充一个python的实现:

 class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
n = len(digits)
temp = [] * n
up =
last = digits[-]
last +=
if last == :
temp[-] =
up =
else:
temp[-] = last for i in range(n-,-,-):
cur = digits[i]
cur += up
if cur == :
temp[i] =
up =
else:
temp[i] = cur
up =
if up == :
temp.insert(,)
return temp

leetcode66的更多相关文章

  1. leetcode-66.加一

    leetcode-66.加一 题意 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个 ...

  2. LeetCode----66. Plus One(Java)

    package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...

  3. [LeetCode66]Plus One

    题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...

  4. [Swift]LeetCode66. 加一 | Plus One

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...

  5. leetCode66:加一

    /** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { if(digits[di ...

  6. 【leetcode-66】 加一

    给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...

  7. 2017-3-7 leetcode 66 119 121

    今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...

随机推荐

  1. JPEG文件格式

    格式:JFIF(JPEG档的交换格式)压缩:JPEG(灰阶影像压缩比约为10:1:彩色影像约为20:1)以JPEG文件格式保存的图像实际上是2个不同格式的混合物:JPEG格式规范本身,用来定义图像的压 ...

  2. 网络流--最大流dinic模板

    标准的大白书式模板,除了变量名并不一样……在主函数中只需要用到 init 函数.add 函数以及 mf 函数 #include<stdio.h> //差不多要加这么些头文件 #includ ...

  3. c++hook全局触控事件

    https://gist.github.com/vbfox/1339671 namespace BlackFox { using System; using System.ComponentModel ...

  4. WC游记

    第一次来WC,感觉这种集训真吼啊 day0 火车上快速补习了莫队,和AC自动姬,AC自动姬以前就会写只不过太久没写忘了我会了= = 莫队只是学习了做法,还没有做过题…… 本来想再复习一下后缀数组,然后 ...

  5. 【vue】Vue调试神器vue-devtools安装

    转载:https://segmentfault.com/a/1190000009682735 前言 vue-devtools是一款基于chrome游览器的插件,用于调试vue应用,这可以极大地提高我们 ...

  6. POJ2182 Lost Cows

    题意 Language:Default Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13448 Accep ...

  7. Linux块设备驱动_WDS

    推荐书:<Linux内核源代码情景分析> 1.字符设备驱动和使用中等待某一事件的方法①查询方式②休眠唤醒,但是这种没有超时时间③poll机制,在休眠唤醒基础上加一个超时时间④异步通知,异步 ...

  8. hasura 的3factor 架构结论

    hasura 是一个很不错的开发团队,开发了好几款,不错的产品,最近的graphql engine 是很热的一款 graphql 引擎,同时团队提出了3factor 系统架构理论 参考网站 https ...

  9. priority_queue

    priority_queue<int> p;//最大值优先,是大顶堆一种简写方式 priority_queue<int,vector<int>,greater<in ...

  10. 使用 Python 连接到 PADS Layout

    使用 Python 连接到 PADS Layout PADS Layout 使用的是 VBA 编程,很多人说 VBA 很简单,但是实在学不会,可能是太笨了. 后来发现 PADS Layout 有 CO ...