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
随机推荐
- 转: Div与table的区别
1:速度和加载方式方面的区别 div 和 table 的差异不是速度,而是加载方式,速度只能是指网络速度,如果速度足够快,是没有差异的: div 的加载方式是即读即加载,遇到 <div> ...
- jquery animate()方法使用的注意事项
当使用 animate() 时,必须使用 Camel 标记法书写所有的属性名,比如,必须使用 paddingLeft 而不是 padding-left,使用 marginRight 而不是 margi ...
- Android drawBitmapMesh扭曲图像
今天介绍一下在Android当中怎么扭曲图像,在Android系统中的Canvas提供了一个drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshH ...
- Apache Jmeter(2)
上一节中,我们了解了jmeter的一此主要元件,那么这些元件如何使用到性能测试中呢.这一节创建一个简单的测试计划来使用这些元件.该计划对应的测试需求. 1)测试目标网站是fnng.cnblogs.co ...
- 移动设备和SharePoint 2013 - 第4部分:定位
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- vs2012 .netFramwork2.0发布到xp
开发环境 windows server2008R2 VS2012 .net Framwork2.0 开发的winform程序 在有的xp系统下不能运行 选择 项目属性=>编译 Build=&g ...
- Yslow&PageSpeed– 诊断各种缓慢症状
Google的PageSpeed和yahoo的yslow是各位不可少的前端工具(同样也都是firebug的插件,安装了firebug之后才可以拥有她们),当各位无法用三寸不烂之舌收拾产品和各种大佬的时 ...
- 理解Mach Port
参考文档: 1. http://robert.sesek.com/thoughts/2012/1/debugging_mach_ports.html 2. Mach 3 Kernel Interfac ...
- Ogre1.8地形和天空盒的建立(一块地形)
转自:http://www.cnblogs.com/WindyMax/ 研究Ogre的程序笔记 编译环境 WIN7 32 VS2008 Ogre的版本 1.8 Ogre的地形算法是采用Geome ...
- 将salt取到的数据处理
#!/usr/bin/env python #coding:utf-8 import json with open('minfo') as f,open('minfoMiddle','w') as f ...