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 ...
随机推荐
- Maven依赖中的scope详解,在eclipse里面用maven install可以编程成功,到服务器上用命令执行报VM crash错误
Maven依赖中的scope详解 项目中用了<scope>test</scope>在eclipse里面用maven install可以编译成功,到服务器上用命令执行报VM cr ...
- 第三方统计分析埋点工具对比,神策、Ptmind、GrowingIO、国双,还有谷歌分析,谁更好?
第三方统计分析埋点工具对比,神策.Ptmind.GrowingIO.国双,还有谷歌分析,谁更好?https://www.colabug.com/2985393.html GA.Mixpanel 和神策 ...
- <转>jmeter(十二)关联之正则表达式提取器
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...
- SQL表分区之一
一般情况下,我们建立数据库表时,表数据都存放在一个文件里. 但是如果是分区表的话,表数据就会按照你指定的规则分放到不同的文件里,把一个大的数据文件拆分为多个小文件,还可以把这些小文件放在不同的磁盘下由 ...
- Action的编写方式
四.Action 的编写方式 : 三种 第一种 创建普通类 不继承任何类,不实现任何接口 Public class HelloAction{ } 第二种 创建类,实现接口action Public ...
- JS笔记—01
1.JS的代码一般在头部写2.当页面载入时,会执行位于body部分的JavaScript当被调用时,位于head部分的JavaScript被执行.3.要对外部的JS文件的一个变量操作,代码是写在内部J ...
- Tomcat配置Manager管理员
修改文件: D:\MyDev\Tomcat\apache-tomcat-7.0.68\conf\tomcat-users.xml 配置内容: <role rolename="mana ...
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFa ...
- HTML5 canvas游戏工作原理
HTML5已经不是一个新名词.它看上去很cool,有很多feature,大多数人普遍看好它的发展.对于我来说,最感兴趣的是它的canvas标签,可以结合Javascript来绘制游戏画面. 我们可以在 ...
- Spring Boot(八):RabbitMQ详解
Spring Boot(八):RabbitMQ详解 RabbitMQ 即一个消息队列,主要是用来实现应用程序的异步和解耦,同时也能起到消息缓冲,消息分发的作用. 消息中间件在互联网公司的使用中越来越多 ...