博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Plus One
阅读量:7060 次
发布时间:2019-06-28

本文共 644 字,大约阅读时间需要 2 分钟。

The idea is just to perform the addition from right to left as usual :-)

Note that the result may be longer than the original digits by 1 number (the carry).

1 class Solution { 2 public: 3     vector
plusOne(vector
&digits) { 4 int c = 1, n = digits.size(); 5 vector
sum(n, 0); 6 for(int i = n - 1; i >= 0; i--) { 7 int val = digits[i] + c; 8 sum[i] = val % 10; 9 c = val / 10;10 }11 if(c) sum.insert(sum.begin(), c);12 return sum;13 }14 };

 

转载于:https://www.cnblogs.com/jcliBlogger/p/4720105.html

你可能感兴趣的文章
将Web应用性能提高十倍的10条建议
查看>>
七个不容易被发现的生成对抗网络(GAN)用例
查看>>
Cisco 安全技术系列之一:2层***防范技术
查看>>
我的友情链接
查看>>
Hello World
查看>>
鼠标放在控件上显示提示信息
查看>>
Bitbucket Project 过大不能 Pull 的解决方法
查看>>
VIM 安装及个别插件配置
查看>>
open***
查看>>
一个批量修改AD信息的小脚本
查看>>
企业证书服务器满5年时间修改
查看>>
iOS应用程序生命周期(前后台切换,应用的各种状态)详解
查看>>
开启golang之旅
查看>>
Android TableLayout表格布局
查看>>
Ftp服务器文件或文件夹的上传和下载
查看>>
四合一简化 WordPress 个人信息,更符合国人使用习惯
查看>>
我的友情链接
查看>>
对于Mysql大量数据查询速度慢的问题
查看>>
tomcat中的server.xml
查看>>
我的友情链接
查看>>