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;
}
}

最新文章

  1. 【原】iOS 同时重写setter和getter时候报错:Use of undeclared identifier &#39;_name&#39;;did you mean &#39;name&#39;
  2. 感知机(perceptron)概念与实现
  3. Unity3D 物体跟随鼠标旋转
  4. Linux 安装 node
  5. udp打洞( NAT traversal )的方法介绍
  6. Sql 之 sql中的强制类型转换
  7. 2005: [Noi2010]能量采集 - BZOJ
  8. ajax 跨域的几种方式
  9. codeforces #268 div2 D
  10. android用shape画虚线,怎么也不显示
  11. JavaScript易混淆知识点小回顾--数组方法与字符串方法;
  12. Leetcode_278_First Bad Version
  13. JSON笔记
  14. 浅析Android Dialog中setContentView()方法
  15. Druid监控页面配置与使用
  16. Opengl正交矩阵 glOrthof 数学原理(转)
  17. ORB-SLAM2(4) 离线双目数据测试
  18. C++类的大小——sizeof(class)
  19. gearman中worker常驻后台,导致MySQL server has gone away
  20. this指针和const成员函数

热门文章

  1. 一天完成把PC网站改为自适应!原来这么简单!
  2. bzoj 2744: [HEOI2012]朋友圈
  3. hdu 4632 Palindrome subsequence
  4. ros与下位机通信常用的c++ boost串口应用
  5. ubuntu php.ini文件位置
  6. opencv+ffmpeg实现avi视频的播放
  7. java.net.SocketException: Too many open files
  8. web安全测试-AppScan
  9. mysql 导入数据库文件到指定数据库
  10. 多动手试试,其实List类型的变量在页面上取到的值可以直接赋值给一个js的Array数组变量