【LeetCode】Add Binary
来源:互联网 发布:数据新闻的发展 编辑:程序博客网 时间:2024/06/14 18:13
题目描述:
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
class Solution {public:string addBinary(string a, string b) {string ret;int inc(0);int LEN = max(a.length(), b.length());for (int i = 0; i <LEN; i++){if (a.length() > i)inc += a[a.length() - i - 1] - '0';if (b.length() > i)inc += b[b.length() - i - 1] - '0';ret = (char)(inc % 2 + '0') + ret;inc >>= 1;}if (inc)ret = '1' + ret;return ret;}};
0 0
- LeetCode: Add Binary
- [Leetcode] Add Binary
- LeetCode Add Binary
- Leetcode: Add Binary
- [Leetcode] Add Binary
- LeetCode : Add Binary
- LeetCode Add Binary
- [LeetCode] Add Binary
- leetcode 58: Add Binary
- leetcode Add Binary
- [LeetCode] Add Binary
- 【leetcode】Add Binary
- [LeetCode]Add Binary
- [leetcode]Add Binary
- LeetCode-Add Binary
- [leetcode] Add Binary
- LeetCode - Add Binary
- leetcode:Add Binary
- 价格折扣的小数位数显示
- 黑马程序员——多线程
- 具有 SUID/SGID 权限的命令运行状态
- Android测试框架介绍
- Servlet生命周期与工作原理
- 【LeetCode】Add Binary
- MFC 创建不规则窗体
- child_process spawn 开辟子进程,执行终端命令,获取数据
- ASP.NET匿名类型
- gcc -I -L -l区别
- jquery 常见问题
- Servlet生命周期
- return与break的区别
- Ubuntu下创建matlab的快捷方式