网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  Plus One

Plus One

分类: IT文章 • 2025-01-07 22:56:02

Given a number represented as an array of digits, plus one to the number.

Code:

class Solution {
public:
    vector<int> plusOne(vector<int> &digits) {
        int n=digits.size();
        bool carry=true;
        for(int i=n-1;i>-1;i--){
            if(digits[i]==9&&carry==1){
                digits[i]=0;
                carry=true;
            }else{
                digits[i]+=carry;
                carry=false;
            }
        }
        if(carry)
            digits.insert(digits.begin(),1);
        return digits;
    }
};

相关推荐

  • SpringBoot+Mybatis-Plus+lombok整合 1.介绍篇 2.创建项目 3.pom文件中引入相关的依赖 4.基础代码准备 5.准备就绪,开始真正体验Mybatis-Plus
  • vue3+element-plus开发学习管理系统
  • 解决iPhone 6 Plus横屏启动界面错乱的问题
  • Adjust one_gadget and hijack exit_hook:hfctf_2020_marksman
  • 转--MyBatis-Plus代码自动生成工具 简介 项目构建
  • Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700 题意: 题解(仅此个人理解): AC代码
  • The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
  • The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
  • Springcloud多模块整合mybatis-plus
  • 使用 Application Loader 上传 IPA 包失败。提示信息:Please sign in with an app-specific password. You can create one at appleid.apple.com
  • Remove Element
  • Insertion Sort List
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号