67. Add Binary
来源:互联网 发布:nba2k15mc霍华德的数据 编辑:程序博客网 时间:2024/05/22 14:30
<span style="font-size:18px;">#include <string>#include <stack>#include <vector>#include <map>#include <algorithm>using namespace std;string addBinary(string a, string b) { int carry = 0; int len = a.size() > b.size() ? a.size() : b.size(); string res; for (int i = 0; i < len; i++) { int na = i < a.size() ? (a[a.size() - 1 - i] - '0') : 0; int nb = i < b.size() ? (b[b.size() - 1 - i] - '0') : 0; int sum = na + nb + carry; res =to_string(sum % 2)+res; carry = sum / 2; } if (carry) res = '1' + res; return res;}int main() { string b = "11"; string a = "11"; string re = addBinary(a, b);}</span>
0 0
- [LeetCode]67.Add Binary
- LeetCode --- 67. Add Binary
- [Leetcode] 67. Add Binary
- [leetcode] 67.Add Binary
- 67. Add Binary
- 【leetcode】67. Add Binary
- 67. Add Binary
- [leetcode] 67.Add Binary
- [leetcode] 67. Add Binary
- 67. Add Binary
- 67. Add Binary
- 【Leetcode】67. Add Binary
- 67. Add Binary
- 67. Add Binary LeetCode
- 67. Add Binary
- 【LeetCode】67. Add Binary
- 67. Add Binary
- 67. Add Binary
- java常量池
- HDU1013Digital Roots
- Codeforces Round #345 (Div. 2) 解题报告
- mysql基于BLACKHOLE复制基础的各种架构
- 第二周项目二-就拿胖子说事
- 67. Add Binary
- 仿微信点击回复,输入框定位到列表的底部
- 第二周项目-就拿胖子说事
- iOS7.0 iphone5边界黑框的问题
- 有关HealthKit的那些事
- HDU杭电5630 ( Rikka with Chess )
- Grunt学习——检查代码完整性
- 206. Reverse Linked List
- DocumentHelper和SAXReader解析XML字符串