LeetCode----66. Plus One(Java)
- package plusOne66;
- /*
- Given a non-negative number represented as an array of digits, plus one to the number.
- The digits are stored such that the most significant digit is at the head of the list.
- */
- public class Solution {
- public static int[] plusOne(int[] digits) {
- int index=digits.length-1;
- digits[index]=digits[index]+1;
- while(digits[index]>=10&&index>0){
- digits[index]=digits[index]%10;
- index--;
- digits[index]=digits[index]+1;
- }
- if (digits[0]>9)
- {
- digits[0]=digits[0]%10;
- int[] result=new int[digits.length+1];
- result[0]=1;
- for (int i=0;i<digits.length;i++){
- result[i+1]=digits[i];
- }
- return result;
- }
- return digits;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] digits={9,9,9,9};
- //System.out.println(plusOne(digits).toString());
- }
- }
LeetCode----66. Plus One(Java)的更多相关文章
- LeetCode第[18]题(Java):4Sum 标签:Array
题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + ...
- LeetCode第[1]题(Java):Two Sum 标签:Array
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- LeetCode第[46]题(Java):Permutations(求所有全排列) 含扩展——第[47]题Permutations 2
题目:求所有全排列 难度:Medium 题目内容: Given a collection of distinct integers, return all possible permutations. ...
- LeetCode第[1]题(Java):Two Sum (俩数和为目标数的下标)——EASY
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- 前端与算法 leetcode 66. 加一
目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...
- Java实现 LeetCode 66 加一
66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...
- Java [Leetcode 66]Plus One
题目描述: Given a non-negative number represented as an array of digits, plus one to the number. The dig ...
- [LeetCode]66.加一(Java)
原题地址: plus-one 题目描述: 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 ...
- leetcode 刷题记录(java)-持续更新
最新更新时间 11:22:29 8. String to Integer (atoi) public static int myAtoi(String str) { // 1字符串非空判断 " ...
- LeetCode 66. Plus One(加1)
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...
随机推荐
- 简单工程使用sbt公共库(sbt-assembly)
只是为了简单实现一个算法,想用到breeze算法库.想把breeze当做external libraryies直接导入工程.可是官网没有,网上搜索更多的是在sbt工程或maven工程下. 后来实现目标 ...
- td内容过长,省略号表示
.word{ min-width:100px; max-width:200px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis ...
- java类集框架图(google找的,备个份)
- [转]从网页Web上调用本地应用程序(.jar、.exe)的主流处理方法
这个方法主要思路是利用自定义URL Protocol来调用应用程序.浏览器在解析到自定义URL Protocol之后,会寻找注册表,然后通过注册表启动相应的程序,然后启动改程序,传入参数.对于我这个项 ...
- C# ArrayList
一.定义 System.Collections.ArrayList类是一个特殊的数组(即动态数组).通过添加和删除元素,就可以动态改变数组的长度. 二.优点 动态的增加和删除元素,实现了ICollec ...
- Jenkins中Jelly基础、超链接、国际化
Jelly基础 参考:https://wiki.jenkins-ci.org/display/JENKINS/Basic+guide+to+Jelly+usage+in+Jenkins UI Samp ...
- Java虚拟机内存管理机制
自动内存管理机制 Java虚拟机(JVM)在执行Java程序过程中会把它所管理的内存划分为若干个不同的数据区域.这些区域都有各自的用途,以及创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,有的区 ...
- controlling the variance of request response times and not just worrying about maximizing queries per second
http://highscalability.com/blog/2010/11/4/facebook-at-13-million-queries-per-second-recommends-minim ...
- php mysql_num_rows() 与 mysql_affected_rows()
mysql_num_rows(data) 函数返回结果集中行的数目. data 结果集.该结果集从 mysql_query() 的调用中得到. 此命令仅对 SELECT 语句有效.要取得被 INSER ...
- jqxGrid 绑定格式化
var cellsrenderer = function(row, columnfield, value, defaulthtml, columnproperties) { ) || (row == ...