LeetCode题解:Plus One
来源:互联网 发布:java并发编程的艺术 编辑:程序博客网 时间:2024/06/03 11:18
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后的值
解决思路:加1以后按照十进制算结果,如果最高位有进位则创建一个新的数组
代码:
public class Solution { public int[] plusOne(int[] digits) { digits[digits.length-1]+=1; for(int i=digits.length-1;i>0;i--) { if(digits[i]==10) { digits[i]=0; digits[i-1]+=1; } } if(digits[0]==10) { int[] res=new int[digits.length+1]; digits[0]=0; res[0]=1; for(int i=1;i<res.length;i++) { res[i]=digits[i-1]; } return res; } return digits; }}
0 0
- LeetCode题解:Plus One
- LeetCode题解:Plus One
- LeetCode题解---Plus One
- LeetCode 题解(228) : Plus One
- Leetcode题解 66. Plus One
- leetcode题解-66. Plus One
- LeetCode题解——Plus One
- Plus One python 题解
- LeetCode: Plus One
- LeetCode Plus One
- [Leetcode] Plus One
- LeetCode: Plus One
- leetcode 33: Plus One
- [LeetCode] Plus One
- [leetCode] Plus One
- 【leetcode】Plus One
- [LeetCode]Plus One
- [leetcode]Plus One
- FV算法
- iOS小问题——关于使用IQKeyBoardManager第三方的坑
- 从业务的层面进行流量控制
- jQuery.Autocomplete实现自动完成功能(详解)
- Webx增加StaffLoginValve
- LeetCode题解:Plus One
- UIView实现动画效果
- 快速理解RequireJs
- 错误:'/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zer
- poj-1129 Channel Allocation
- Network Saboteur(POJ_2531)
- 解读jquery源码时记录的一些知识点
- Spark入门实战系列--6.SparkSQL(上)--SparkSQL简介
- TwemProxy(nutcracker)参数选项及配置解析