您的位置:首页 > 其它

leetcode Plus One

2015-05-31 11:10 274 查看
基础题

题目链接这里

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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: