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 ...
随机推荐
- Java综合高级篇
1.你用过哪些集合类? 大公司最喜欢问的Java集合类面试题 40个Java集合面试问题和答案 java.util.Collections 是一个包装类.它包含有各种有关集合操作的静态多态方法. ja ...
- golang学习笔记7 使用beego swagger 实现API自动化文档
golang学习笔记7 使用beego swagger 实现API自动化文档 API 自动化文档 - beego: 简约 & 强大并存的 Go 应用框架https://beego.me/doc ...
- GUI编程实例
function varargout = GUI013(varargin) % GUI013 MATLAB code for GUI013.fig % GUI013, by itself, creat ...
- Robot Framework 自动化测试--部署篇
一.产品介绍 Robot Framework是一个基于Python的,可扩展的关键字驱动的测试自动化框架.它是为了端 到端的验收测试(End-To-End Acceptance Test)以及验收测试 ...
- js获取浏览器信息
function message() { txt = "<p>浏览器代码名: " + navigator.appCodeName + "</p>& ...
- JS笔记—01
1.JS的代码一般在头部写2.当页面载入时,会执行位于body部分的JavaScript当被调用时,位于head部分的JavaScript被执行.3.要对外部的JS文件的一个变量操作,代码是写在内部J ...
- Python调用大漠插件
Python版本要用32位的?我去官网下载,太慢了,就在腾讯软件里面下载了一个,结果实验成功 import win32com.client dm = win32com.client.Dispatch( ...
- Java操作Solr之SolrJ
添加SolrJ的jar包 solrj是访问Solr服务的java客户端,提供索引和搜索的请求方法,SolrJ通常在嵌入在业务系统中,通过SolrJ的API接口操作Solr服务, <depende ...
- 关于innodb_flush_log_at_trx_commit、innodb_flush_method、innodb_log_block_size和fsync()、O_DIRECT、iops、云盘的关系与总结
想着整理关于innodb_flush_log_at_trx_commit.innodb_flush_method.innodb_log_block_size和fsync().O_DIRECT.iops ...
- pycharm 安装激活操作
pycharm 安装激活操作 什么是 PyCharm PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管 ...