leetcode做题总结,题目Plus One 2012/04/02
来源:互联网 发布:贝克汉姆维多利亚知乎 编辑:程序博客网 时间:2024/06/07 00:11
题目是用数组表示的一个数进行加1。我的做法是用一个变量做进位标志量,然后一位一位计算即可。
public int[] plusOne(int[] digits) { int num = digits.length-1; int add=1; while(num>=0){ if(add==1){ if(digits[num]==9){ digits[num]=0; }else{ digits[num]++; add=0; } } num--; } if(add==1){ int[] fin = new int[digits.length+1]; fin[0]=1; for(int i=1;i<digits.length+1;i++){ fin[i]=digits[i-1]; } return fin; } return digits; }
0 0
- leetcode做题总结,题目Plus One 2012/04/02
- 【leetcode】第66题 Plus One 题目+解析+JAVA代码
- leetcode做题总结,题目Generate Parentheses 2012/02/12
- leetcode做题总结,题目Partition List 2012/04/30
- leetcode做题总结,题目Sort Colors 2012/04/08
- leetcode做题总结,题目Combinations 2012/04/18
- leetcode做题总结,题目Palindrome Number 2012/01/04
- leetcode做题总结,题目Add Two Numbers /Add Binary 2011/11/01&2012/04/02
- leetcode做题总结,题目Remove Duplicates from Sorted ArrayI/II--- 2012/02/16-04/19
- leetcode做题总结,题目Rotate List 2012/03/27
- leetcode做题总结,题目Gray Code 2012/05/20
- leetcode做题总结,题目Valid Parentheses 2012/01/30
- leetcode做题总结,题目Valid Sudoku 2012/03/03
- leetcode做题总结,题目Permutation Sequence 2012/03/27
- leetcode做题总结,题目Anagrams 2012/03/19
- 【LeetCode】Plus One && 【九度】题目1198:a+b
- leetcode做题总结,题目Search in Rotated Sorted Array I/II 2012/03/02-12/04/09
- leetcode做题总结,题目Swap Nodes in Pairs 2012/02/14
- hibernate+spring的整合思路加实例
- 面试知识:操作系统、计算机网络、设计模式、Linux编程,数据结构总结
- poj 2479
- CoCos2Dx学习笔记之环境配置
- 设置Windows 8.1屏幕自动旋转代码, Auto-rotate function code
- leetcode做题总结,题目Plus One 2012/04/02
- hdoj 2098 分拆素数和
- adboost
- 38_抖动的动画效果&动画的插入器
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
- 【HDU】4873 ZCC Loves Intersection 数学
- poj 1988 Cube Stacking(数据结构:带权并查集)
- BUPT Summer Journey #test4 C
- leetcode做题总结,题目Set Matrix Zeroes 2012/04/06