leetcode 66. Plus One

TRK-MPC5634M开发板实战:从硬件解析到CAN、ADC外设驱动调试 在嵌入式系统开发,尤其是汽车电子和工业控制领域,微控制器(MCU)是核心执行单元。其工作原理基于处理器内核、存储器和丰富的外设接口协同工作,通过软件编程实现对硬件的精确控制。这种技术价值在于能够为严苛环境提供可靠、实时的控制解决方案。典型的应用场景包括汽车车身控制、网关、电池管理系统以及工业自动化设备。本文聚焦于恩智浦(NXP)基于Power Architecture e200z0内核的汽车级MCU——MPC5634M,并以其官方评估板TRK-MPC5634M为平台,深入探讨其硬件设计逻辑、软件环境搭建及核 阅读详情

Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1:

Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:

Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.

用一个数组代表一个数字,让用数组输出这个数字+1后的结果

思路:
按正常的从右至左做加法,同时加上进位
需要注意的是在最左边有进位的时候因为原有的数组长度不够,需要分配一个新的数组

**注意不能用digits[i] = (digits[i] + plus) % 10,然后再plus = (digits[i] + plus) /10
因为前面的操作下digits[i]已经更新,后面再用更新后的digits[i]就会出错,所以用sum变量来保存相加的和

//0ms
    public int[] plusOne(int[] digits) {
        int plus = 0;
        int len = digits.length;
        int sum = 0;
        
        sum = digits[len - 1] + 1 + plus;
        digits[len - 1] = sum % 10;
        plus = sum / 10;
        
        for (int i = len - 2; i >= 0; i--) {
            sum = digits[i] + plus;
            digits[i] = sum % 10;
            plus = sum / 10;
        }
        
        if (plus > 0) {
            int[] result = new int[len + 1];
            for (int i = len - 1; i >= 0; i--) {
                result[i + 1] = digits[i];
            }
            result[0] = plus;
            return result;
        }
        
        return digits;
    }
51智能小车(双轮) 前几天接了个小单子,是一个基于51单品机的作品,发现自己对小车的认识还是不太🆗。也算是完成了任了的;欢迎各位小伙伴来多多交流,大家一起进步。最后有需要单片机课程设计的小伙伴滴滴我哦(有偿)。企鹅:2397746994。 阅读详情

相关推荐

AltiumDesigner 高效封装库管理 -- samacsys插件实战指南

本文详细介绍了如何利用samacsys插件高效管理AltiumDesigner封装库。通过实战指南,指导用户完成插件安装、云端元件搜索与放置,并分享将海量资源整合为个人标准库的管理策略,从而大幅提升PCB设计效率与可靠性,杜绝封装错误。

weixin_28285943的博客 125

LeetCode 66. Plus One

LeetCode 66. Plus One Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the l...

zhaohaibo的博客 276

C语言版数字锁相放大器实现指南:从复数运算到嵌入式MCU移植的坑我都帮你踩了

本文详细介绍了C语言实现数字锁相放大器的关键技术,包括复数运算优化、嵌入式MCU移植的实战经验及内存管理策略。针对STM32等资源受限平台,提供了从浮点到定点数转换的优化方案,帮助工程师高效处理微弱信号提取问题。

weixin_30721077的博客 432

LeetCode 66. Plus One

题目来源:https://leetcode.com/problems/plus-one/ 问题描述 66.Plus One Easy Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer. The digits are stored such that...

da_kao_la的博客 178

天祥TX-1C单片机开发板-秒表程序

郭天祥TX-1C开发板实现秒表程序 附开发板图片和原理图 代码 #include <reg52.h> sbit key1=P3^4; //按键S2 sbit key2=P3^5; //按键S3 sbit U1=P2^6; //LED位选 sbit U2=P2^7; //LED片选 unsigned char code ledchar[]={ /...

Run_long_road 3511

Python学习24:中国古代数学问题——物不知数(Python123)

意思是说有一些物品,不知道有多少个,3个3个数的话,还多出2个;5个5个数则多出3个;7个7个数也会多出2个。题目为‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬‬:今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?现假设物品总数不超过n (n

weixin_60530224的博客 2万+

Leetcode 66. Plus One 加一

Leetcode 66. Plus One 加一 标签: Leetcode 题目地址:https://leetcode-cn.com/problems/plus-one/ 题目描述 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字。 你可以假设除了整数 0 之外,这个整数不会以零开头。 示例 1: 输入: [...

CoderWangSon 264

C#利用S7netplus实现西门子S7_200_SMART PLC高效点位监控与操作

本文详细介绍了如何使用C#结合S7netplus开源库高效监控与操作西门子S7-200 SMART PLC的点位。内容涵盖从开发环境搭建、建立通信连接,到核心的点位读写、批量数据处理及字节与位数组转换等关键技术,并提供了构建稳定监控程序的架构与避坑指南,帮助开发者快速实现上位机与PLC的稳定数据交互。

rum55的博客 315

[Leetcode]66.Plus One

[leetcode] 66. Plus One题目链接:https://leetcode.com/problems/plus-one/Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most signifi

weixin_37553155的博客 207

用LT1166+MOS管打造实验室级恒流源:闭环反馈与推挽驱动的深度调优

本文详细介绍了基于LT1166电流模式控制器与MOS管推挽架构的实验室级恒流源设计方法。通过闭环反馈调优和动态响应优化,实现带宽达100kHz、纹波低于0.1%的高性能恒流输出,适用于精密仪器校准和半导体测试等场景。重点解析了系统架构设计、MOS管选型策略以及频率响应测试等关键技术要点。

weixin_29290379的博客 202

Pythia: A Customizable Hardware Prefetching Framework Using Online Reinforcement Learning——“预取”论文解读

参考传送门: 1. Hardware Prefetching笔记 2. 全球百科——缓存预取 3. 百度百科——缓存数据预期技术 目录0. 什么是Hardware Prefetching(本节内容不包括在论文中)1. 简介1.1 关于Hardware Prefetching的一些关键信息1.2 现阶段方法的缺陷1.3 论文团队的目标1.4 核心思想2. 必要的背景知识介绍2.1 强化学习(Reinforcement learning)2.2 为什么说强化学习是一个好的解决思路3. 解决方法与思路3.1 Py

Pinkgranite86的博客 2165

[勇者闯LeetCode] 66. Plus One

[勇者闯LeetCode] 66. Plus OneDescription Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero

fanguzhai的博客 234

用示波器抓取同步Buck自举电容波形:从充电回路到SW节点振铃的完整分析

本文通过实测TI TPS54561和MPS MPQ4572同步Buck芯片,详细解析了自举电容在充电、维持和放电三个工作阶段的波形特征。重点揭示了电感泄放回路与充电回路重叠时,在SW节点引发的振铃现象及其产生机理,并提供了串联阻尼电阻等有效的工程抑制方法。文章结合示波器实测,为硬件工程师提供了从波形观测到问题调试的完整实践指南。

weixin_29276847的博客 371

LeetCode力扣 66. 加一 Plus One 题解代码 JavaScript

https://leetcode-cn.com/problems/plus-one/ /** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { var i,j; for(i=digits.length-1;i>=0;--i) { digits[i] += 1; if(digits[i] >= 10)

Coding home - 漂流瓶jz 633

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

leetcode-66. Plus One

leetcode-66. Plus OneGiven a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 it

myan991的博客 457

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【LeetCode】66. Plus One

LEETCode66 传送门 解法: 需要向面试官问的问题有,可能有负数吗?数字在digits中是如何存储的,正向还是反向?开头会出现0吗? 实现上推荐的方法比我的方法更直接一些。放在循环中的if判断+return比while中的判断更易读。 Python源码: Runtime:20 ms, faster than57.47%ofPythononline sub...

weixin_42344158的博客 233

Leetcode 66.加一(Plus One)

Leetcode 66.加一 1 题目描述(Leetcode题目链接)   给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。你可以假设除了整数 0 之外,这个整数不会以零开头。 输入: [1,2,3] 输出: [1,2,4] 解释: 输入数组表示数字 123。 输入: [4,3,2,1] 输出: [4,3,2,2] 解...

qq_39378221的博客 219

【细节处理】LeetCode 66. Plus One

LeetCode 66. Plus One 博客转载自:http://www.cnblogs.com/grandyang/p/4079357.html Solution1: class Solution { public: vector&lt;int&gt; plusOne(vector&lt;int&gt;&amp; digits) { int i = digits...

Allenlzcoder的博客 260

leetcode刷题记录-66. Plus One

leetcode刷题记录-66. Plus One 1.题目要求   Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except...

zhaizhan501的博客 215

LeetCode: 66. Plus One

LeetCode: 66. Plus One题目描述Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number

杨领well的专栏 1435

[leetcode]66. Plus One

[leetcode]66. Plus One Analysis paper终于提交啦,但是过的可能性很小的感觉 —— [ 坚持坚持啊 ] Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored...

weixin_32135877的博客 167

[Leetcode] 66. Plus One

Problem:https://leetcode.com/problems/plus-one/ Solution: Copy array class Solution { public int[] plusOne(int[] digits) { int l = digits.length; for(int i = l-1; i >= 0; i--) {...

Renoler的博客 168

LeetCode 66. Plus One(加一) -- c语言

66. Plus One Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, an...

d_benhua的博客 308
上一篇: leetcode 57. Insert Interval(插入区间)
下一篇: mac Xcode opencv 配置
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值