Java for LeetCode 066 Plus One
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.
解题思路:
往一个用数组表示的数里面加1,注意下数据溢出即可,JAVA实现如下:
public int[] plusOne(int[] digits) {
for(int i=digits.length-1;i>=0;i--){
digits[i]++;
if(digits[i]<=9)
return digits;
digits[i]=0;
}
int[] result=new int[digits.length+1];
result[0]=1;
return result;
}
Java for LeetCode 066 Plus One的更多相关文章
- Java for LeetCode 216 Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Java for LeetCode 214 Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- Java for LeetCode 212 Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- Java for LeetCode 211 Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...
- Java for LeetCode 210 Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- Java for LeetCode 200 Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Java for LeetCode 154 Find Minimum in Rotated Sorted Array II
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- Java for LeetCode 153 Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
随机推荐
- python 学习笔记1(序列;if/for/while;函数;类)
本系列为一个博客的学习笔记,一部分为我原创. 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 1. print 可以打印 有时需要 ...
- ElasticSearch插件安装Head、Kopf与Bigdesk
ElasticSearch-Head ElasticSearch-Head 是一个与Elastic集群(Cluster)相交互的Web前台. ES-Head的主要作用 它展现ES集群的拓扑结构,并且可 ...
- BZOJ3720 Gty的妹子树
Description 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕…… Gty神(xian)犇(chong)从来不缺妹子…… 他来到了一棵妹子树下,发现每 ...
- 换了XCode版本之后,iOS应用启动时不占满全屏,上下有黑边
原因是没有Retina4对应的启动图片,解决方法很简单,就是把Retina4对应的图片给补上就只可以了
- HDU 5497 Inversion
Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description You have ...
- Mysql 学习-索引的设计原则
索引的设计不合理或者缺少索引都会对数据库和应用程序的性能造成障碍.高效的索引对获的良好性能非常重要.设计索引是,应该考虑一下准则: (1)索引并非语讹夺越好,若一个表中有大量索引,不仅占用磁盘空间,而 ...
- 代码重构-3 用Tuple代替 out与ref
返回单一值是良好的编程习惯 原代码: public LotteryViewModel ValidateLottery(LotteryBaseData baseData, int authTime, o ...
- Java初学(二)
一.数据类型 在定义Long或者Float类型变量的时候,要加L或f(大小写无关,只是便于识别,建议不要小写L) 整数默认是int,浮点数默认是double 二.java字符 java语言采用的是Un ...
- 如何使用网盘托管git项目
话说近年来git已经成为项目源代码管理的标准工具,有不少免费托管网站可供使用,详情参考这篇文章: http://www.cnblogs.com/zdz8207/archive/2012/05/20/2 ...
- Memcache的部署和使用(转)
一.memcache简介 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力. Mem ...