LeetCode_66. Plus One_数组加一
2016-01-21 16:21
393 查看
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.
数值小时可通过,但是没有考虑到数值的范围。待会再改:
一把辛酸泪…………………………
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 len = digits.length; int sum = 0; int sum1 = 0; int[] res= new int[len]; int[] res1= new int[len+1]; for(int i = 0; i< digits.length; i++){ sum +=Math.pow(10,len-i-1)*digits[i]; } for(int i = 0; i<digits.length; i++){ sum1 += Math.pow(10,len-i-1)*1; } if(sum1*9==sum){ sum= sum+1; res1[0]=1; for(int j=1;j<res1.length;j++){ res1[j]=0; } return res1; }else{ for(int j=0;j<res.length;j++){ res[res.length-j-1]=sum%10; sum=sum/10; } return res; } } }
数值小时可通过,但是没有考虑到数值的范围。待会再改:
一把辛酸泪…………………………
相关文章推荐
- Java学习第8天(5):面向对象-继承-接口
- android启动 uboot启动 rom制作
- Scala implicit
- AndroidManifest.xml 文件详解
- 用UIColloctionView 实现cell放大以及无限轮播
- 读书笔记--互联网必读《长尾理论》作者克里斯.安德森
- 手机端META详细解释
- 定时任务 - quartz
- 前端总结(设计向)
- java 获取当前时间月加1 ,年加1
- iOS 保持界面流畅的技巧
- str_replace中的匹配空白符,必须用双引号
- 给 Android 开发者的 RxJava 详解
- css网站
- 字符串流 istringstream 和 ostringstream 的用法
- 字符串流 istringstream 和 ostringstream 的用法
- Hadoop YARN学习之核心概念(2)
- Java学习第8天(4):面向对象-继承-abstract
- Spring Integration实例代码分析之basic--http
- Hadoop YARN学习之核心概念(2)