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

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

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 };

 

转载地址:http://wycxl.baihongyu.com/

你可能感兴趣的文章
javascript-放大镜
查看>>
集合框架源码学习之LinkedList
查看>>
Python 安全类目推荐 (持续更新)
查看>>
流媒体知识
查看>>
安装Oracle 11g RAC R2 之Linux DNS 配置
查看>>
8Manage O2O门店管理,快速提升利润
查看>>
[机器学习01]What's machine learing?
查看>>
SQL Server 2008 R2学习心得
查看>>
Asp.net生成htm静态文件的两种途径
查看>>
java面试-深入理解JVM(六)——JVM性能调优实战
查看>>
jsonobject 遍历 org.json.JSONObject
查看>>
oracle之 11.2.0.4 bbed安装
查看>>
bootstrap11-基本的表格布局
查看>>
firewalld
查看>>
利用python socket管理服务器
查看>>
为保护人类,DeepMind开发专项测试软件,以保障AI算法安全性
查看>>
Exchange 2013sp1邮件系统部署-(六)
查看>>
消息队列(二)RocketMQ介绍
查看>>
优雅的在终端中编写Python
查看>>
python install on windows 10
查看>>