Leetcode66-Plus One-Eassy
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的更多相关文章
- leetcode-66.加一
leetcode-66.加一 题意 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个 ...
- LeetCode----66. Plus One(Java)
package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...
- [LeetCode66]Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- [Swift]LeetCode66. 加一 | Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- leetCode66:加一
/** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { if(digits[di ...
- 【leetcode-66】 加一
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...
- leetcode66
public class Solution { public int[] PlusOne(int[] digits) { ]; < ) { digits[digits.Length - ]++; ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- IO多路复用 IO异步
一.概念说明 同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的环境给出的答案是不同的.所以先限定一下本文的环境.本文讨论的背景是Linux环境下的network I ...
- RSA 加密 解密 公钥 私钥 签名 加签 验签
http://blog.csdn.net/21aspnet/article/details/7249401# http://www.ruanyifeng.com/blog/2013/06/rsa_al ...
- html5水平方向重力感应
html5图片随手机重力感应而移动 <!DOCTYPE html> <html lang="zh-cn"><head><meta http ...
- 51Nod 1090 3个数和为0
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1090 思路:排序 三个for循环 但是要控制循环 不能从头开 ...
- 前端框架VUE----nodejs中npm的使用
NPM是什么? 简单的说,npm就是JavaScript的包管理工具.类似Java语法中的maven,gradle,python中的pip. 安装 傻瓜式的安装. 第一步:打开https://node ...
- yield的理解
yield的理解:yield命令是异步两个阶段的分界线需要先对迭代器和生成器进行理解: 迭代器:是一种支持next()操作的对象.它包含一组元素,当执行next()时,返回其中一个元素:当所有元素都被 ...
- 从实践出发:微服务布道师告诉你Spring Cloud与Spring Boot他如何选择
背景 随着公司业务量的飞速发展,平台面临的挑战已经远远大于业务,需求量不断增加,技术人员数量增加,面临的复杂度也大大增加.在这个背景下,平台的技术架构也完成了从传统的单体应用到微服务化的演进. 系统架 ...
- OLED屏幕那些次像素有趣的排列方式
http://www.dzsc.com/data/2016-6-2/109856.html 我们今天的重点内容为倒数第二列内容的上半部分,也就是RGB排列和Pentile排列.在介绍OLED屏幕时候我 ...
- Pytorch-学习记录 卷积操作 cnn output_channel, etc.
参考资料: pytorch中文文档 http://pytorch-cn.readthedocs.io/zh/latest/
- Docker学习笔记之编写 Docker Compose 项目
0x00 概述 通过阅读之前的小节,相信大家对 Docker 在开发中的应用已经有了一定的了解.作为一款实用的软件,我们必须回归到实践中来,这样才能更好地理解 Docker 的实用逻辑和背后的原理.在 ...