66. 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.
代码如下:
public class Solution {
public int[] plusOne(int[] digits) {
int i=digits.length-1;
int c=0;
digits[i]=digits[i]+1;
try{
while(digits[i]>=10&&i>=0)
{
digits[i]=digits[i]-10;
c=1;
i--;
if(i>=0)
{
digits[i]=digits[i]+c;
c=0;
}
}
}catch(ArrayIndexOutOfBoundsException e){}
if(c==1)
{
int[] num= new int[digits.length+1];
num[0]=1;
for(int j=0;j<digits.length;j++)
num[j+1]=digits[j];
return num;
}
return digits;
}
}
66. Plus One的更多相关文章
- 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题[zz]
使用vs2012/2013配置opencv编译出现问题: 1>------ 已启动生成: 项目: Win32ForOpenCV245, 配置: Debug Win32 ------ 1> ...
- Scala 深入浅出实战经典 第66讲:Scala并发编程实战初体验
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传
[源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...
- Effective Java 66 Synchronize access to shared mutable data
synchronized - Only a single thread can execute a method or block at one time. Not only does synchro ...
- #有如下值集合[11,22,33,44,55,66,77,88,99,90...],将所有大于66值保存至字典的一个key中,将小于66的值保存至大二个key的值
#!/usr/bin/env python #有如下值集合[11,22,33,44,55,66,77,88,99,90...],将所有大于66值保存至字典的一个key中,将小于66的值保存至大二个ke ...
- leetcode 66
66. Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- 【LeetCode】66 & 67- Plus One & Add Binary
66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- Part 64 to 66 Talking about Indexers in C#
Part 64 - C# Tutorial - How and where are indexers used in .net Part 65 - C# Tutorial - Indexers in ...
- 全球最流行的66款App的共同规律
根据苹果AppStore.Google Play.App Annie.亚马逊 AppStore及Windows Phone 应用商店历年的公开数据统计,以下66个非游戏类应用正在全球范围内流行,持续时 ...
- ssh-copy-id -i ~/.ssh/id_rsa.pub admin@172.17.42.66
ssh-copy-id -i ~/.ssh/id_rsa.pub admin@172.17.42.66
随机推荐
- jquery删除原事件
$(document).ready(function(){ var fn = $("#exportCsv").attr( "onclick" ); // 获取原 ...
- c++ 普通高精乘
//第一次提交全错了,太过相信自己了. //给我教训是注意循环后变量的值,和pascal不一样. //就不贴错误代码了. //codevs3118 高精度练习之除法 #include<cstdi ...
- Oracle、Mysql、Sql Server语句的区别
1.空值的处理——判断是否为空,为空时取一个值,不为空时取另一个值 1).Sql Server 中 ISNULL(check_expression,replacement_value) 解释:如果ch ...
- Linux-Unix版本介绍
转自: http://blog.163.com/li_zhuangs/blog/static/195698098201182411360635/ < DOCTYPE html PUBLIC -W ...
- CSU 1111 D(Contest #3)
有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请 ...
- fdisk分区
查看文件系统: # df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 20G 1.1G 18G 6% /tmpfs 1.9G 0 1.9 ...
- poj2129 dp
//Accepted 320 KB 47 ms //dp //dp[i][j]=1 表示用s1的前i个,s2的前j个字符能构成s3的前i+j-1个字符 //dp[i][j]=0 表示构不成 //dp[ ...
- webservice实验一
实验目的:安装jdk1.6_21以后的版本,利用JAX-WS API自己发布webservice并调用,以及用wsimport生成webservice客户端代码调用一个免费的web服务(如webxml ...
- linux基础命令学习(三)Vim使用
1. # vim 1.txt 命令模式: a i o A I O x X yy dd p G dw de h j k l f H M B a --- append 追加 在光标所在位置后追加一个字符 ...
- loadrunner录制时弹出invalid application path!please check if application exists对话框
问题:oadrunner录制时弹出invalid application path!please check if application exists对话框 原因:IE浏览器地址不对,需要手动重新选 ...