【Leetcode】 66. Plus One

来源:互联网 发布:淘宝忘记密码怎么办 编辑:程序博客网 时间:2024/06/15 18:19

原题

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.

public class Solution {    public int[] plusOne(int[] digits) {        int len = digits.length;        for(int i =0 ;i < len ; i++){            if(i==len -1 && digits[i]== 9){                int[] result = new int[len+1];                result[0] = 1;                for(int j = 1; j< len+1 ; j++){                    result[j] = 0;                }                return result;            }            if(digits[i]==9) continue;            break;        }        plus(digits, len-1);        return digits;    }        void plus(int[] ints, int index){        if(ints[index]!= 9){            ints[index]+=1;        }else{            ints[index] = 0;            plus(ints, index -1);        }    }}

runtime 0ms是什么鬼?