67. Add Binary
来源:互联网 发布:activiti engine源码 编辑:程序博客网 时间:2024/06/08 10:09
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 result=""; int a_length=a.length()-1; int b_length=b.length()-1; int sum=0; int count=0; while(a_length>=0||b_length>=0) { int a_temp=0<=a_length?(a[a_length]-'0'):0; int b_temp=0<=b_length?(b[b_length]-'0'):0; sum=a_temp+b_temp+count; result=to_string(sum%2)+result; count=sum/2; a_length=a_length>=0?(a_length-1):-1; b_length=b_length>=0?(b_length-1):-1; } if(count!=0) result=to_string(count)+result; return result; }};
阅读全文
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代码实现
- 大型网站系统与JAVA中间件理解
- python gevent打补丁后会影响kafka库的使用(关于epoll)
- 轻松反编译C#的DLL
- 关于HTPP的相关内容
- 67. Add Binary
- 测试某些代码的执行时间
- QCOM GPS Modem侧定位信息上报流程
- 誉天华为HCNP-Big Data认证
- Array属性和方法
- python中 对文件的读写操作 以及如何边写入 边保存flush()
- method
- idea激活码,留备用
- Android Recycleview的用法