[LC] 66. Plus One
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.
Example 1:
Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:
Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.
class Solution {
    public int[] plusOne(int[] digits) {
        if (digits == null || digits.length == 0) {
            return digits;
        }
        for (int i = digits.length - 1; i >= 0; i--) {
            if (digits[i] < 9) {
                digits[i] += 1;
                return digits;
            }
            digits[i] = 0;
        }
        int[] newDigits = new int[digits.length + 1];
        newDigits[0] = 1;
        return newDigits;
    }
}
[LC] 66. Plus One的更多相关文章
- [LC]66题 Plus One (加1)
		①英文题目 Given a non-empty array of digits representing a non-negative integer, plus one to the integer ... 
- LOJ10043
		题目描述 原题来自:HNOI 2002 Tiger 最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger 拿出了公司的账本,账本上记录了公司成 ... 
- LC T668笔记 & 有关二分查找、第K小数、BFPRT算法
		LC T668笔记 [涉及知识:二分查找.第K小数.BFPRT算法] [以下内容仅为本人在做题学习中的所感所想,本人水平有限目前尚处学习阶段,如有错误及不妥之处还请各位大佬指正,请谅解,谢谢!] !! ... 
- 四种比较简单的图像显著性区域特征提取方法原理及实现-----> AC/HC/LC/FT。
		laviewpbt 2014.8.4 编辑 Email:laviewpbt@sina.com QQ:33184777 最近闲来蛋痛,看了一些显著性检测的文章,只是简单的看看,并没有深入的研究,以 ... 
- “LC.exe”错误
		错误“LC.exe”已退出,代码为 -1. 可能的原因是: 这个第三方组件是个商业组件,他在组件的主使用类定义了 LicenseProvider(typeof(LicFileLicenseProvid ... 
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
		使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ... 
- 解决VS下“LC.exe已退出,代码为-1”问题
		今天使用VS2015开发一个Winform程序,手一抖拖错了一个第三方控件,然后将其去掉并删除相关的引用,结果导致了LC.exe错误:"Lc.exe已退出,代码为-1 ". 经过上 ... 
- 解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析
		许可证编译器 (Lc.exe) 的作用是读取包含授权信息的文本文件,并产生一个可作为资源嵌入到公用语言运行库可执行文件中的 .licenses 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ... 
- Lc.exe已退出,代码为-1
		编译项目,出现提示"Lc.exe已退出,代码为-1" . 解决办法: 意思就是把licenses.licx这个文件里的内容删除,但是文件还在(此时是个空文件),发生这个问题的原 ... 
随机推荐
- 转载:微信小程序源码提取反编译
			转载来源:www.51xuediannao.com/xiaochengxu/019c08cc.html 一.前言 微信小程序源码提取反编译,听起来很屌,其实还是简单的,基本是傻瓜式操作.要想拿到微信小 ... 
- Ubuntu编译protobuf
			个人博客地址:http://www.bearoom.xyz/2019/08/24/ubunt-protobuf/ 因为编译了tensorflow C++的版本,然后提示protobuf的版本不对应引起 ... 
- 吴裕雄--天生自然深度学习TensorBoard可视化:改造后的mnist_train
			import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ... 
- PAT Advanced 1023  Have Fun with Numbers (20) [⼤整数运算]
			题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ... 
- PAT Advanced 1038 Recover the Smallest Number (30) [贪⼼算法]
			题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ... 
- kubectl 常用命令一
			1.kubectl logs <options> <PodName> -f -p, --previous --since= No. --since-time= --tail ... 
- ios uiimagepickercontroller 选择相册或者拍照上传
			首先需要实现UIImagePickerControllerDelegate 代理 实现其imagePickerController 方法 这里用于选择图片或的拍照回调 //调用相机拍照 或者 图库选 ... 
- 40)类与类之间的关系(has   use   is)
			1)类与类之间的关系 一般就是三类: ①has--A ②use--A ③is-----A ①has--A 包含关系,用以描述一个类由多个“部件构成”.实现has--A关系用类成员表示, 即一个类 ... 
- 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第四天】
			https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ... 
- office 无法打开xlsx文件的问题
			1. 设置content-type和header response.setContentType("application/vnd.openxmlformats-officedocument ... 
