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

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

题目链接https://leetcode.com/problems/plus-one/

 

这是digit这类题里最简单的一道了,这类题基本都不难,但是需要把几个boundary case考虑到,这道题里需要考虑的是进位之后首位的情况。其他case以后遇到再提。

 

class Solution {public:    vector
plusOne(vector
& digits) { int carry = 1; vector
result; for(int i = digits.size() - 1; i >= 0; i--) { int cur = digits[i] + carry; result.push_back(cur % 10); carry = cur / 10; } if(carry > 0) result.push_back(carry); reverse(result.begin(), result.end()); return result; }};

 

转载于:https://www.cnblogs.com/walcottking/p/4430829.html

你可能感兴趣的文章
集合(NSArray,Set,NSMutableArray,NSDictionary)
查看>>
Sum Root to Leaf Numbers
查看>>
Windows Server: 将虚拟机迁移到 Azure (以阿里云为例)
查看>>
C#实现身份证号码验证的方法
查看>>
docker swarm集群
查看>>
docker 部署jar包
查看>>
在Nginx容器安装Keepalived后端项目双机热备
查看>>
Docker打包部署前端项目与负载均衡
查看>>
一款阿里开源的 Java 诊断工具
查看>>
阿里云云盾安全事件提醒:挖矿程序
查看>>
redis安装(linux)
查看>>
mysql自定义函数多表更新:update_order_relation()
查看>>
UUID与时间戳
查看>>
SimpleDateFormat 线程安全的解决方案--DateTimeFormatter
查看>>
mysql不常用查询
查看>>
win下PowerShell的簡單使用
查看>>
windows下安装redis
查看>>
redis簡單命令
查看>>
git问题记录
查看>>
如何将jar包打包到本地maven仓库
查看>>