当前位置:网站首页>LeetCode+ 66 - 70 高精度、二分专题
LeetCode+ 66 - 70 高精度、二分专题
2022-06-28 06:55:00 【小雪菜本菜】
加一
算法标签:数组、数学

给我们一个整数,这个整数是用一个数组来表示的,在这个整数的基础上加 1,加 1 之后还是用数组来表示,数组的最高位放到第 0 个位置,次高位放到第 1 个位置,假设这个数组是没有前导 0,其实就是给了一个很长的整数,模拟加法的过程

由于最高位可能会进位,所以需要先把数组翻转,要让个位在第 0 个位置,十位在第 1 个位置,从个位开始做,每次计算当前这一位的值是多少,看一下有没有进位,如果有进位就进一位
每一次当前位置上的数应该怎么计算呢?
个位上应该是原来位置上的数加上 1,再加上进位,加上 1 可以看成是前面进了一位,每一位的数字就可以看成是这一位原本的数字加上进位,进位可以是 0 也可以是 1,加上之后,当前位置的数就是这个数的和除以 10 的余数,进位就是这个数的和除
边栏推荐
- [C language] detailed explanation of C language to obtain array length
- Floating and positioning
- 4~20mA输入/0~5V输出的I/V转换电路
- 三极管驱动无刷电机
- 强化学习——格子世界
- 【网络教程】IPtables官方教程--学习笔记1
- Iframe switching in Web Automation
- Alert pop-up processing in Web Automation
- freeswitch设置最大呼叫时长
- It will cost 700 yuan to realize this issue. Does anyone do it?
猜你喜欢

「杰伦熊」暴跌96.6% 明星带货NFT为何遇冷?

推荐10个好用到爆的Jupyter Notebook插件,让你效率飞起

AutoCAD C polyline self intersection detection

金山云团队分享 | 5000字读懂Presto如何与Alluxio搭配

My MVVM open source project "travel epidemic prevention app" has been released

Eyebeam advanced settings

Triode driven brushless motor

Libuv框架echo-server.c源码详解(TCP部分)

Pytorch RNN learning notes

Interpretation of Blog
随机推荐
Promotion intégrale et ordre des octets de fin de taille
Floating and positioning
4~20ma input /0~5v output i/v conversion circuit
【Rust日报】 2020-04-23 Rust 1.43.0 发布
Servlet value passing JSP
Overview, implementation and use of CRC32
整型提昇和大小端字節序
Cmake tips
代码没写错,渲染页面不显示原因
《微信小程序-基础篇》带你了解小程序中的生命周期(一)
【网络教程】IPtables官方教程--学习笔记1
Some habits of it veterans in the workplace
ImportError: cannot import name 'ensure_ dir_ Possible solutions for exists'
Alert pop-up processing in Web Automation
Boost the rising point | yolov5 combined with alpha IOU
Causes of wechat applet compilation page blank bug
"Jay bear" plummeted by 96.6%. Why is NFT with star goods cold?
【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2
MySQL (II) - basic operation