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

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

由于最高位可能会进位,所以需要先把数组翻转,要让个位在第 0 个位置,十位在第 1 个位置,从个位开始做,每次计算当前这一位的值是多少,看一下有没有进位,如果有进位就进一位
每一次当前位置上的数应该怎么计算呢?
个位上应该是原来位置上的数加上 1,再加上进位,加上 1 可以看成是前面进了一位,每一位的数字就可以看成是这一位原本的数字加上进位,进位可以是 0 也可以是 1,加上之后,当前位置的数就是这个数的和除以 10 的余数,进位就是这个数的和除
边栏推荐
- RN7302三相电量检测(基于STM32单片机)
- 小程序页面设置100%高度还是留白怎么办?
- Iphone6plus enters the list of antique products netizen: I'm still using it
- "Jay bear" plummeted by 96.6%. Why is NFT with star goods cold?
- 助力涨点 | YOLOv5结合Alpha-IoU
- Create a gson object that formats the time zone. JSON parsing time formatting zoneddatetime
- Freeswitch uses origin to dialplan
- KMP string
- Freeswitch uses Mod_ Shot module plays mp3
- Triode driven brushless motor
猜你喜欢

"Jay bear" plummeted by 96.6%. Why is NFT with star goods cold?

Error reporting - resolve core JS / modules / es error. cause. JS error

推荐几款0代码、免费、现学现用的可视化工具

From the beginning of redis learning to take-off, this article is all for you

Some habits of it veterans in the workplace

CRC32概述以及实现和使用

MySQL (I) - Installation

AutoCAD C polyline self intersection detection

Speech enhancement - spectrum mapping

Niubi 666, this project makes web page making as simple as building blocks
随机推荐
Rn7302 three-phase electric quantity detection (based on STM32 single chip microcomputer)
VM332 WAService. js:2 Error: _ vm. Changetabs is not a function
饿久了,大脑会进入“省电模式”!感官被削弱,还看不清东西丨爱丁堡大学...
js正则表达式系统讲解(全面的总结)
编译原理期末复习
JDBC learning (I) -- implementing simple CRUD operations
Linked list (I) - remove linked list elements
Promotion intégrale et ordre des octets de fin de taille
Drop down list processing in Web Automation
C language tutorial
Build your jmeter+jenkins+ant
MySQL(一)——安装
4~20mA输入/0~5V输出的I/V转换电路
小程序页面设置100%高度还是留白怎么办?
Speech enhancement - spectrum mapping
The code is correct, and the rendering page does not display the reason
Shell script one click deployment (MySQL)
RN7302三相电量检测(基于STM32单片机)
Freeswitch uses origin to dialplan
什么是一致性哈希?可以应用在哪些场景?