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

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

Given a number represented as an array of digits, plus one to the number.
[解题思路]
加位与进位。模拟。
[Code]
1:  vector
plusOne(vector
&digits) { 2: // Start typing your C/C++ solution below 3: // DO NOT write int main() function 4: int cary=1, sum =0; 5: vector
result(digits.size(),0); 6: for(int i = digits.size()-1; i>=0; i--) 7: { 8: sum = cary+digits[i]; 9: cary = sum/10; 10: result[i] = sum%10; 11: } 12: if(cary >0) 13: { 14: result.insert(result.begin(), cary); 15: } 16: return result; 17: }

转载于:https://www.cnblogs.com/codingtmd/archive/2012/12/30/5078976.html

你可能感兴趣的文章
微信公众平台开发(64)航班动态
查看>>
获取真机使用的语言
查看>>
[Lydsy2017年4月月赛]抵制克苏恩题解
查看>>
8-5 泛型类型擦除
查看>>
正文处理命令及tar命令
查看>>
GDI+ 绘制多行文本,自动换行。
查看>>
[转载] ASCII、UTF8、Uncicode编码下的中英文字符大小
查看>>
实习第三周小记-----生活在于经历 分类: 程序人生 ...
查看>>
Leetcode题目:Minimum Depth of Binary Tree
查看>>
从微软官网下载联机入门丛书
查看>>
PHP三种访问控制模式(public、protected、private)解析
查看>>
python numpty 中shape的用法
查看>>
浅谈C#中的结构
查看>>
使用单元素枚举实现单例
查看>>
前端基本知识
查看>>
将excel中的数据转为json格式
查看>>
字典操作
查看>>
使用source创建一个新项目(将本地项目文件和github远程库链接)
查看>>
运行问题,如何修改APACHE的监听端口和密码
查看>>
Solaris服务管理
查看>>