66. Plus One(easy)

66. Plus One [easy] (Python) 题目链接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 significant digit 阅读详情

Easy

7141303FavoriteShare

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.

 

C++:

/*
 @Date    : 2019-01-24 20:16:23
 @Author  : 酸饺子 (changzheng300@foxmail.com)
 @Link    : https://github.com/SourDumplings
 @Version : $Id$
*/

/*
https://leetcode.com/problems/plus-one/
 */

class Solution
{
public:
    vector<int> plusOne(vector<int>& digits)
    {
        do_add(digits, digits.size() - 1);
        return digits;
    }

    void do_add(vector<int>& num, int d)
    {
        if (d == -1)
        {
            num.insert(num.begin(), 1);
            return;
        }
        if (num[d] == 9)
        {
            num[d] = 0;
            do_add(num, d - 1);
        }
        else
            ++num[d];
        return;
    }
};

Java:

 

/**
 * @Date    : 2019-01-24 20:26:00
 * @Author  : 酸饺子 (changzheng300@foxmail.com)
 * @Link    : https://github.com/SourDumplings
 * @Version : $Id$
 *
 * https://leetcode.com/problems/plus-one/
*/

class Solution
{
    public int[] plusOne(int[] digits)
    {
        return doAdd(digits, digits.length - 1);
    }

    public int[] doAdd(int[] digits, int d)
    {
        if (d == -1)
        {
            int[] res = Arrays.copyOf(digits, digits.length+1);
            int l = res.length;
            for (int i = l - 1; i != 0; --i)
            {
                res[i] = res[i-1];
            }
            res[0] = 1;
            return res;
        }
        else
        {
            if (digits[d] == 9)
            {
                digits[d] = 0;
                return doAdd(digits, d - 1);
            }
            else
            {
                ++digits[d];
                return digits;
            }
        }
    }
}

 

Easy 66题 Plus One question: Given 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. Solusti 阅读详情

相关推荐

Star CCM+中的物性参数(定值、多项式、查表)

仿真过程中我们一定会遇到设置物性参数的问题,对于固定的物性参数还好说,直接输入一个固定的值即可。但是对于冷却液、气体、两相流等,物性参数是随着温度或温度和压力变化的。此时就涉及到多项式和查表。首先创建物理连续体,选择计算模型。

2201_75375391的博客 2969

[Easy] 66. Plus One

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 list, and ...

Bungehurst 397

CMakeTestCCompiler.cmake错误解决

CMakeTestCCompiler.cmake错误解决欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 最近编译项目的时候,遇到一个cmake的错误,具体错误信息如下: /path-to-pr

昨夜星辰的博客 2万+

[Leetcode 66, Easy] Plus One

[Leetcode 66, Easy] Plus One

算法的实践 841

COMSOL报错调试总结(不定期更新)

COMSOL报错调试总结1. 可定位错误1.1 除零错误1.2 未定义变量值1.3 边界条件/材料属性等缺失2. 难定位错误2.1. 装配期间内存不足 官方给的案例总是非常完美,运行流畅,结果完美。但是自己做模型时候就总是报错,而且不像自己coding的程序那样可以明确定位哪里出了bug。这里把我碰到的一些报错问题以及调试方法记录下来~ 部分来源于以下参考来源: http://wap.sciencenet.cn/blog-1467490-1118453.html?mobile=1 1. 可定位错误 以下错误

jessica0307的博客 8万+

Windows非分页缓冲池内存泄漏实战:PoolMon与RAMMap高效排查指南

本文详细介绍了Windows系统中非分页缓冲池内存泄漏的实战排查方法。当系统出现卡顿且内存占用异常增长时,通过RAMMap工具快速定位非分页缓冲池异常,并利用PoolMon监控内核内存分配标签,精准锁定泄漏源。文章提供了从确认症状、安装工具到使用findstr命令溯源驱动文件的完整五步排查流程,并总结了常见泄漏标签与解决方案,帮助用户高效解决深层系统内存问题。

weixin_28455801的博客 1036

Leetcode 66. Plus One (Easy) (cpp)

Leetcode 66. Plus One (Easy) (cpp)

还是需要多学习!闷声大发财,这是坠吼的! 456

不只是CPU主频:深入解析英飞凌Aurix TC3xx各外设时钟树(CAN、以太网、Flash时序如何配置)

本文深入解析英飞凌Aurix TC3xx系列微控制器的外设时钟树配置,涵盖CAN、以太网和Flash时序的优化方法。通过详细分析时钟系统架构、关键外设配置及多外设协同设计策略,帮助工程师实现高性能汽车电子控制单元(ECU)开发。特别关注系统时钟的灵活配置与EMC优化技巧,提升系统实时性和可靠性。

weixin_29189373的博客 405

LeetCode Array Easy 66. Plus One

Description 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 li...

baobo4566的博客 185

2025_NIPS_Better Tokens for Better 3D: Advancing Vision-Language Modeling in 3D Medical Imaging

近年来,3D医学成像领域的视觉语言建模取得了显著进展,这得益于大规模带配对自由文本报告的计算机断层扫描(CT)语料库、更强大的架构以及高性能预训练模型。这些进展推动了自动报告生成和文本条件3D图像合成等应用的发展。然而,现有方法在处理高分辨率、长序列体积数据时仍面临挑战:对比预训练往往导致视觉编码器与临床语言错位,而基于切片的令牌化会模糊精细解剖结构,降低下游任务的诊断性能。

c_cpp_csharp的专栏 95

Mybatis面试题(基础篇)

(1)mybatis是支持定制化SQL、存储过程以及高级映射的优秀的持久层框架。(2)mybatis避免了几乎所有的JDBC代码(说明了mybatis底层用的就是JDBC,只不过是封装了)和手动设置参数以及获取结果集。(3)mybatis可以使用简单的XML或注解用于配置和原始映射,将接口和Java的pojo映射成数据库中的记录。

qq_38196449的博客 1695

[LeetCode]Q66. Plus One-Easy

LeetCode刷题思路 Q66. Plus One 关于对数组元素的修改 涉及递归

weixin_45554810的博客 248

【论文复现】——基于LM优化的NDT点云配准算法

传统的正态分布变换配准算法处理初始位姿变换相差较大的两帧点云时,存在无法收敛或者陷入局部最小值的问题。为了提高算法的收敛性能,提出了一种基于LM方法改进的三维正态分布变换配准算法。

点云侠的博客 1174

leetcode 66. Plus One [easy][java]

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 ...

inkhk的博客 147

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

LeetCode 66.Plus One Easy/Array

文章目录Plus One(加一)1.Description2.Example3.Solution1.自己的笨方法 Plus One(加一) 1.Description Given a non-empty array of digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most significant digit is at the h

押切徹的博客 154

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode - Easy - 66. Plus One

Topic Array Description https://leetcode.com/problems/plus-one/ Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most significant digit is at the head of the li

KISS 236

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

66. Plus One (Easy)

Given 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. 题目的意思是给定一个数,这个数以

记录技术,记录生活 3158

66. Plus One 难度:easy

题目: 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 0 itself.

luoyingmin的博客 281

LeetCode】66.Plus One(easy)解题报告

【LeetCode】66.Plus One(easy)解题报告 题目地址:https://leetcode.com/problems/plus-one/description/ 题目描述:   Given a non-negative integer represented as a non-empty array of digits, plus one to the integer....

郝春雨的博客 174

Leetcode笔记整理—easy篇—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 list, and each el...

曦酱的思维工厂 237

66. Plus One - Easy

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, and each element...

weixin_33798152的博客 147

LeetCode Top Interview Questions 66. Plus One (Java版; Easy)

welcome to my blog LeetCode Top Interview Questions 66. Plus One (Java版; Easy) 题目描述 Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stor...

littlehaes的博客 204

leetcode 66. Plus One (easy)

简答的高精度加法问题,唯一考虑进位就行了 class Solution { public: vector<int> plusOne(vector<int> &digits) { int c = 1; for (auto i = digits.rbegin(); i != digits.rend(); i++) { *i += c; c...

Rh's blog 171

Leetcode - 66 - Plus One (easy)

Given anon-emptyarray of decimal digitsrepresenting a non-negative integer, incrementone 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 contains a single digit. You...

xin_rong的博客 145

【LeetCode】 66. Plus One 加一(Easy)(JAVA)

【LeetCode】 66. Plus One 加一(Easy)(JAVA) 题目地址: https://leetcode.com/problems/plus-one/ 题目描述: Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits ar...

qq_16927853的博客 176

Easy 14 Plus One(66)

Description 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 0 itself. Th

holy的博客 343
上一篇: 1101. Quick Sort (25)
下一篇: 1110. Complete Binary Tree (25)
SourDumplings
博客等级 码龄9年 21粉丝 306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值