标签:leetcode解题报告 算法 java
https://oj.leetcode.com/problems/plus-one/public class Solution { public int[] plusOne(int[] digits) { int flag = 1; int i = 0; for(i=digits.length-1;i>=0;i--) { digits[i] = digits[i] + flag; if(digits[i]>9) { <span style="white-space:pre"> </span>flag = 1; <span style="white-space:pre"> </span>digits[i] = 0; <span style="white-space:pre"> </span>} else { <span style="white-space:pre"> </span>return digits; <span style="white-space:pre"> </span>} } if(i==-1&&flag==1) { <span style="white-space:pre"> </span>int[] newdigits = new int[digits.length+1]; newdigits[0] = 1; for(i=1;i<=digits.length;i++) { newdigits[i] = digits[i-1]; } return newdigits; } else { return digits; } } }
标签:leetcode解题报告 算法 java
原文地址:http://blog.csdn.net/worldwindjp/article/details/42590537