Leetcode Problem.67—Add Binary
来源:互联网 发布:淘宝发票抬头设置 编辑:程序博客网 时间:2024/06/11 09:19
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
My C++ solution!
string addBinary(string a, string b) { int len_a=a.length();int len_b=b.length();string result;int temp;int jinwei=0;int i=0,j=0;while(len_a||len_b){temp=0;int r;if(len_a){temp=temp+a[len_a-1]-'0';len_a--;}if(len_b){temp=temp+b[len_b-1]-'0';len_b--;}temp=temp+jinwei;result=result.insert(0,1,temp%2+'0');jinwei=temp/2;}if(jinwei==1)result.insert(0,1,'1');return result; }
0 0
- Leetcode Problem.67—Add Binary
- [leetcode 67] Add Binary
- [LeetCode 67]Add Binary
- leetcode-67 Add Binary
- leetcode || 67、Add Binary
- LeetCode 67 Add Binary
- Add Binary - LeetCode 67
- LeetCode---(67) Add Binary
- leetcode[67]:Add Binary
- leetcode 67 Add Binary
- Leetcode# 67 Add Binary
- leetcode 67: Add Binary
- leetcode-67-Add Binary
- Leetcode#67||Add Binary
- [Leetcode]#67 Add Binary
- leetcode 67Add Binary
- Leetcode 67:Add Binary
- leetcode 67 Add Binary
- 关于Intent的Flag属性的讲解
- Git Server搭建
- 软件设计之自顶向下
- 【HDU】5247-找连续数(直接暴力)
- iOS显示隐藏状态栏
- Leetcode Problem.67—Add Binary
- Leetcode Problem.83—Remove Duplicates from Sorted List
- ueditor富文本
- C语言字节对齐
- springmvc下的基于token的防重复提交
- C++中const、volatile、mutable的用法
- log4net的简单应用
- SMB协议
- SIFT算法详解