leetcode Plus One

基础题
题目链接这里

public class Solution {
    public int[] plusOne(int[] digits) {
         int []result=digits;
        int jinwei=1;

        for(int i=result.length-1;i>=0;i--)
        {
            result[i]=jinwei+result[i];
            jinwei=0;
            if(result[i]==10)
            {
                result[i]=0;
                jinwei=1;
            }
        }
        if(jinwei==0)
        {
            return result;
        }
        else
        {
            int []result1=new int[result.length+1];
             System.arraycopy(result,0,result1,1,result.length);
            result1[0]=1;
           return result1;
        }
    }
}

你可能感兴趣的:(leetcode Plus One)