大数相加
来源:互联网 发布:淘宝延长收货最多几天 编辑:程序博客网 时间:2024/06/04 19:49
Given two numbers represented as strings, return sum of the numbers as a string.
string addStr(const string& num1, const string& num2){int i = num1.size()-1;int j = num2.size()-1;string ans = "";int ad = 0;while (i >= 0 && j >= 0){int cur = num1[i] - '0' + num2[j] - '0' + ad;char c = cur % 10 + '0';ad = cur / 10;ans += c;--i;--j;}while (i >= 0){int cur = num1[i] - '0' + ad;char c = cur % 10 + '0';ad = cur / 10;ans += c;--i;}while (j >= 0){int cur = num2[j] - '0' + ad;char c = cur % 10 + '0';ad = cur / 10;ans += c;--j;}if (ad > 0){char c = ad + '0';ans += c;}return string(ans.rbegin(), ans.rend());}
0 0
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 大数相加
- 定义变量的位置 @interface VS @implementation
- 为listview,gridview添加布局动画效果(通过资源文件方式)
- STL之容器、迭代器及算法知识总结
- 合并两个已排序的链表
- linux 下搭建从coturn服务器(穿透服务器)
- 大数相加
- PHP扩展开发-接收参数、返回参数
- typedef与#define的区别
- Contains Duplicate III 是否包含重复元素系列3
- Bitcode真机测试要修改为 NO
- oracle 监听hang住问题
- 查找WPF控件的默认Style的方法
- 理解Clojure STM 软件事务性内存
- laravel nginx配置