[LeetCode]Plus One
发布日期:2021-11-22 02:48:49
浏览次数:8
分类:技术文章
本文共 549 字,大约阅读时间需要 1 分钟。
1Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
题意:给一个数的数组形式(例如78 digits[0]=7,digits[1]=8),每一位加1,返回一个数组形式。注意99 digits[0]=9,digits[1]=9,返回应该为nums[0]=1,nums[1]=0,nums[2]=0,100
code:
public int[] plusOne(int[] digits) { for(int i = digits.length-1; i>=0; i--){ if(digits[i]<9){ digits[i]++; return digits; } digits[i] =0; } int[] nums = new int[digits.length+1]; nums[0]=1; return nums; }
转载地址:https://blog.csdn.net/zxdfc/article/details/48625521 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月31日 08时05分25秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
np.ascontiguousarray(array)
2019-04-26
from scipy import misc 读取和保存图片
2019-04-26
关于Batch Normalization
2019-04-26
关于PGGAN
2019-04-26
后台挂起,让服务器运行,客户端崩溃也可以继续运行
2019-04-26
SQL中的token含义
2019-04-26
网络的权重初始化示例
2019-04-26
python的各种推导式
2019-04-26
集合的运算关系
2019-04-26
Python的位置参数、默认参数、可变参数(*args)、关键字参数(**kwargs)
2019-04-26
匿名函数lambda
2019-04-26
git上传代码到远程仓库的命令行步骤
2019-04-26
Android解决网络加载大图片OOM的问题
2019-04-26
设计模式之单例模式
2019-04-26
JAVA的引用类型
2019-04-26
Android 解决Dialog导致软键盘无法隐藏的问题
2019-04-26
初学Flutter--Assets资源文件
2019-04-26
Unity3d学习笔记
2019-04-26