当前位置:网站首页>加一问题
加一问题
2022-08-07 05:12:00 【捣蛋鬼大师】
代码均为
php版本
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。最高位数字存放在数组的首位, 数组中每个元素只存储单个数字,数字遇到大于9则进一位
示例
输入: [4,3,2,1]
输出: [4,3,2,2]
解释: 输入数组表示数字 4321。
输入: [9,8,2,1]
输出: [0,0,9,3,2]
解释: 输入数组表示数字 9821。
代码
$num1 = [9,9,9,6];
$j = count($num1) - 1;
while($j >= 0){
if($num1[$j] >= 9){
$num1[$j] = 0;
}else{
$num1[$j]++;
}
$j--;
}
if($j == -1){
array_unshift($num1,0);
}
边栏推荐
- 利用matlab工具箱的pid参数科学整定方法
- 线性代数学习笔记4-4:求解非齐次线性方程组Ax=b,从秩的角度看方程
- Centos安装Redis(保姆级)
- 线性代数学习笔记5-2:(正交的)投影、投影矩阵、A^T A、最小二乘法LS
- Explain in detail the big game behind Justin Sun's "Sea of Stars", space travel needs more people to participate
- 正则表达式笔记
- 打印sql各种方法汇总
- ros1-gazebo创建世界和机器人模型(单线雷达、多线雷达、相机)
- Ansible - Explanation and Application of Playbook Playbook
- 编写一个程序将数组去除其中重复部分数据,最终得到一个升序且不重复的数组
猜你喜欢

微信小程序安装vant组件库过程

Talk about 7 magic skills of Redis memory optimization

【无标题】

页面底部出现横向滚动条解决方法

线性代数学习笔记6-4:行列式的应用(用伴随矩阵求逆矩阵、克莱姆法则解方程、行列式求面积/体积)

预约家教老师上门辅导小程序开发制作功能介绍

STC不同系列单片机的软串口位时间函数差异

Supplement to Linear Algebra Study Notes 2-3: Abstract Vector Spaces

MySQL advanced 1 - underlying data structure B+ tree

Differences in the soft serial port bit time function of different series of STC microcontrollers
随机推荐
用C语言实现简单得通讯录
C51 基本函数、中断函数和库函数的详解
centos安装redis服务
线性代数学习笔记5-2:(正交的)投影、投影矩阵、A^T A、最小二乘法LS
Redis 发布订阅操作
[Graduation Project] Automatic gas station refueling system based on STM32 - Internet of Things, microcontroller, embedded
SSM整合------全过程
Supplement to Linear Algebra Study Notes 2-3: Abstract Vector Spaces
2021-01-05
洛谷P1189 `SEARCH`
The setting and clearing of the inconsistency between the data displayed in the Excel cell and the actual data
Redis关闭持久化
移动端预览(双指缩放移动)富文本编辑器上传的图片
Network cable
SSM的简单整合
happens-before rule and thread singleton safety exercise
Excel合并单元格测试代码
课程预约小程序制作功能介绍
Small P weekly, Vol. 14
洛谷P1201 贪婪的送礼者Greedy Gift Givers