LeetCode Plus One
2015-10-11 22:01
453 查看
问题:
解决:
[code]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.
解决:
[code]public class Solution { public int[] plusOne(int[] arr) { if(arr[arr.length - 1] != 9) { arr[arr.length - 1] += 1; return arr; } else { for(int index =arr.length - 1;index >= 0;index--) { if(arr[index] != 9) { arr[index] += 1; for(int i = index+1;i<arr.length;i++) arr[i] = 0; return arr; } if(index == 0) { int [] res = new int[arr.length+1]; for(int j = arr.length;j>=1;j--) { res[j] = 0; } res[0] = 1; return res; } } } return arr; } }
相关文章推荐
- Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记
- 20135321余佳源-信息安全系统设计基础第五周学习总结
- Currency Exchange(Bellman-Ford)
- 第 二 十 七 天 :HA 高 可 用 集 群 搭 建
- Palindromes _easy version
- Windows系统下的TCP参数优化(注册表\TCPIP\Parameters)
- Collections.reverseOrder()
- UVALive 4987 EvacuationPlan(dp,贪心)
- 前端网页内容性能优化
- 程序的机器级表示 第四周10.5~10.11
- Another Crisis
- 广播域和冲突域
- hiho #1241 : Best Route in a Grid 【dp 求解质因子2和5的最少匹配个数】
- Java Android常用术语英文简称及释义
- CPaintDC、CClientDC、CWindowDC和CMetaFileDC类的主要特点及区别
- Swift中使用Reactive获取网络数据,并字典转模型。
- 20135304刘世鹏——信息安全系统设计基础第四周学习总结
- 类内存分配和this指针
- 图的遍历,非递归版本,深度优先遍历
- CSDN成长史——用心写博客