Add Binary
来源:互联网 发布:高级算法工程师 编辑:程序博客网 时间:2024/06/11 14:41
class Solution {
public:
string addBinary(string a, string b) {
int len1=a.size();
int len2=b.size();
string s;
int result=stoi1(a)+stoi1(b);
int i=0;
if(result==0) return "0";
while(result)
{
s+=(result%2+'0');
//i++;
result=result/2;
}
reverse(s.begin(),s.end());
return s;
}
int stoi1(string &a)
{
int temp;
int result=0;
for(int i=0;i<a.size();i++)
{
temp=a[i]-'0'+0;
result=result*2+temp;
}
return result;
}
};
public:
string addBinary(string a, string b) {
int len1=a.size();
int len2=b.size();
string s;
int result=stoi1(a)+stoi1(b);
int i=0;
if(result==0) return "0";
while(result)
{
s+=(result%2+'0');
//i++;
result=result/2;
}
reverse(s.begin(),s.end());
return s;
}
int stoi1(string &a)
{
int temp;
int result=0;
for(int i=0;i<a.size();i++)
{
temp=a[i]-'0'+0;
result=result*2+temp;
}
return result;
}
};
0 0
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- Add Binary
- 理解 Ruby Symbol (Ruby中的符号)
- stm32的MDA应用设置
- 常见八种安卓开发报错的方式
- 如何禁止系统自动更新后重启
- Ubuntu chrome安装
- Add Binary
- 判断IP是否合法
- 去掉UITableView中多余空行
- 翻转二叉树
- 搭建scrapy抓取javascript动态数据的爬虫
- Android View的生命周期
- android客户端从服务器端获取json数据并解析
- poj 2373 dp(灌溉草场)
- Android4.2下 WebView的addJavascriptInterface漏洞解决方案