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

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

思路:digits[i] +1 有两种结果:(1)digits[i] < 9: 不进位 (2)digits[i] = 9: digits[i] = 0;

class Solution {
public int[] plusOne(int[] digits) { for (int i = digits.length - 1; i >=0 ; i--){
if (digits[i] < 9) {
digits[i] ++;
return digits;
}
digits[i] = 0;
} int[] newNumber = new int[digits.length + 1];
newNumber[0] = 1;
return newNumber;
}
}

Leetcode66-Plus One-Eassy的更多相关文章

  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. leetcode66

    public class Solution { public int[] PlusOne(int[] digits) { ]; < ) { digits[digits.Length - ]++; ...

  8. Install and run DB Query Analyzer 6.04 on Microsoft Windows 10

          Install and run DB Query Analyzer 6.04 on Microsoft Windows 10  DB Query Analyzer is presented ...

  9. DB Query Analyzer 6.04 is distributed, 78 articles concerned have been published

        DB Query Analyzer 6.04 is distributed,78 articles concerned have been published  DB Query Analyz ...

  10. How to create DB2 user function easily by DB Query Analyzer 6.03

    How to create DB2user function easily by DB Query Analyzer 6.03 Ma Genfeng (Guangdong Unitoll Servic ...

随机推荐

  1. flask实战-个人博客-使用蓝本模块化程序

    使用蓝本模块化程序 实例化flask提供的blueprint类就创建一个蓝本实例.像程序实例一样,我们可以为蓝本实例注册路由.错误处理函数.上下文处理函数,请求处理函数,甚至是单独的静态文件文件夹和模 ...

  2. 如何给webview页面自定义404页面

    //示例地图类 package com.can2do.doimobile.news; import android.os.Bundle; import android.os.Handler; impo ...

  3. 在MyEclipse中使用javadocAPI文档

    开始啦 1.打开MyEclipse,选中要导出的项目,右击Exprot弹出窗口,选择java----javadoc点击next到下一界面. 2.选出要导出的项目或要添加的项目,在browse中选择路径 ...

  4. Spring数据库开发

    Spring的数据库开发 #Spring中JDBC模板的作用 JDBC模板负责数据库资源管理和错误处理: #熟悉Spring  JDBC的配置 配置数据源和jdbc模板 <?xml versio ...

  5. Mysql去掉html标签函数

    函数 SET GLOBAL log_bin_trust_function_creators=; DROP FUNCTION IF EXISTS fnStripTags; DELIMITER | CRE ...

  6. jquery .width和css("width", )区别

    1.$.fn.width会根据是否是borderBox来计算新的宽度,如果是borderBox,会额外加上padding和border的宽度,计算时只是按照px来,用rem做单位会出错: 2.$.fn ...

  7. CentOS ping: unknown host 解决方法

    如果ping命令返回如下错误,那主要的可能性就是系统的DNS设置有误 [root@CentOS5 ~]# ping www.sina.com.cn ping: unknown host www.sin ...

  8. 【题解】Luogu P4344 [SHOI2015]脑洞治疗仪

    原题传送门:P4344 [SHOI2015]脑洞治疗仪 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 珂朵莉树好题啊 我一开始一直Re65 后来重构代码就ac了,或许是rp问题 ...

  9. 问题:oracle 12c rac数据库服务器的home目录丢失问题解决2018-06-25 18:30

    问题原因:是由于运维粗心,在缩容/home(此目录下挂载了逻辑卷lv_home)时没有先缩小文件系统(resize2fs)也没有备份,导致home数据损坏,重启时系统无法正常启动 解决方案:跳过此ho ...

  10. windows线程池之I/O完成端口(IOCP)

    对于这个学习主要参考博客 http://blog.csdn.net/neicole/article/details/7549497