leetcode解题方案--066--Plus One
来源:互联网 发布:碳谱数据库 编辑:程序博客网 时间:2024/06/05 05:34
题目
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
分析
数组的末尾加1
考虑进位数组长度也有可能变
class Solution { public static int[] plusOne(int[] digits) { int add = 0; int sum = digits[digits.length-1] + 1; digits[digits.length-1] = sum%10; add = sum/10; int index = digits.length-2; while (add!=0 && index>=0) { digits[index] = digits[index]+1; if (digits[index] == 10) { add = 1; digits[index] = 0; } else { add = 0; } index--; } if (add!=0) { int[] ret = new int[digits.length+1]; System.arraycopy(digits, 0, ret,1,digits.length); ret[0] = add; return ret; } return digits; }}
阅读全文
0 0
- leetcode解题方案--066--Plus One
- [LeetCode] Plus One 解题报告
- 【LeetCode】Plus One 解题报告
- LeetCode 066 Plus One
- LeetCode 066 Plus one
- LeetCode 066 Plus One
- LeetCode 066 Plus One
- leetcode 066 plus one
- LeetCode 066 Plus One
- LeetCode 066 Plus One
- LeetCode Plus One Java版解题报告
- [leetcode] 66. Plus One 解题报告
- [Leetcode] 66. Plus One 解题报告
- LeetCode(066) Plus One (Java)
- leetCode 66.Plus One (+1问题) 解题思路和方法
- Leetcode 66. Plus One 加一! 解题报告
- [leetcode] 369. Plus One Linked List 解题报告
- leetcode解题之66 # Plus One Java版
- Excel在统计分析中的应用—第八章—假设检验-两总体方差的假设检验2(FTEST及F-检验宏)
- PJ的情书:纯模拟,桶排去重加上pair,用vector进行cmp重载
- Swagger2与Spring mvc集成
- windows和vmware共享文件夹
- synchronized详解
- leetcode解题方案--066--Plus One
- SeleniumIDE的安装、使用入门
- HTML5新特性2(拖放事件/历史管理/延时加载JS)
- 【关于基于物理染的阅读材料整理】READINGS ON PHYSICALLY BASED RENDERING
- 日常运维-6
- leetcode解题方案--067--Add Binary
- String 类型切割成数组-转int数组-升列排序-拼接字符串、需求 有如下一个字符串 "91 27 46 38 50"
- 程序员面试、算法研究、编程艺术、红黑树、机器学习5大系列集锦
- (三十二)session共享问题