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. 《DSP using MATLAB》Problem 3.18

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  2. hdu2079 选课时间(题目已修改,注意读题) 母函数

    计算数的和的种类,母函数裸题 #include<stdio.h> #include<string.h> ],c2[],a,b; int main(){ int T; while ...

  3. Vue中的“混合”——mixins使用方法

    混合是一种灵活的分布式复用 Vue 组件的方式.混合对象可以包含任意组件选项.以组件使用混合对象时,所有混合对象的选项将被混入该组件本身的选项.当组件和混合对象含有同名选项时,这些选项将以恰当的方式混 ...

  4. GridColumn (Column Layout and Auto Width)

    Namespace:DevExpress.XtraGrid.Columns Assembly:DevExpress.XtraGrid.v16.2.dll https://documentation.d ...

  5. Vue2.x整合百度地图JavaScript方案

    代码很整合很简单,主要记录操作思路,注意回调百度地图api的回调函数 @/utils/map.js let Map = { BaiDuMap(ak) { return new Promise(func ...

  6. sysbench 0.5 基准测试

    sysbench 介绍 SysBench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.它主要包括以下几种方式的测试: cpu性能 磁盘io性能 调度程 ...

  7. 全选,反选,获取值ajax提交

    //必须先加载jquery //加载 弹出框插件 artdialog http://www.planeart.cn/demo/artDialog/ /****全选反选*开始**/ $(document ...

  8. PHP中imagecopyresampled参数详解

    原文链接http://blog.csdn.net/ajaxchen_615/article/details/5941181 做php缩微图程序,用到了imagecopyresampled函数,在网上找 ...

  9. Qt5布局管理(一)——QSplitter分割窗口类

    转载:LeeHDsniper 概述 本文首先通过三个实例分别介绍Qt5的分割窗口QSplitter类.停靠窗口QDockWidget类.堆栈窗体QStackedWidget类,然后介绍布局管理器的使用 ...

  10. linux下maven项目clean失败

    今天在linux下创建了一个项目自动化发布的脚本,在执行到 mvn clean package -Dmaven.test.skip=true 的时候,项目clean失败 查下下度娘,windows下导 ...