Add Binary字符数字相加,字符串合成
2024-10-08 02:15:48
class Solution {
public:
string addBinary(string a, string b) {
string longer=a.length()>b.length() ? a:b;
string shorter=a.length()>b.length() ? b:a;
int add=;
int j=longer.length()-;
for(int i=shorter.length()-;i>=;--i,--j){
if(shorter[i]-''+longer[j]-''+add>){
longer[j]=''+(shorter[i]-''+longer[j]-''+add)%;
add=;
}else{
longer[j]=''+(shorter[i]-''+longer[j]-''+add)%;
add=;
}
}
while(j>=){
if(longer[j]-''+add>){
longer[j]='';
add=;
}else{
longer[j]=longer[j]+add;
add=;
}
--j;
}
if(add)
longer.insert(,,'');
return longer;
}
};
最新文章
- android UI控件小记
- 十一、Manipulators
- Replication的犄角旮旯(六)-- 一个DDL引发的血案(上)(如何近似估算DDL操作进度)
- 【Swift学习】Swift编程之旅---集合类型之数组(六)
- specify a file path to store the seed
- 《Play for Java》学习笔记(四)Controller
- 如何让你的Apache支持include文件解析和支持shtml的相关配置
- IIS 7.0 and Web Farms
- web前端开发分享-css,js入门篇(转)
- imacros实现Excel数据自动录入到网页中
- GNU名称解析
- 推荐几款主流的Css Reset
- 六:在线工具网站,让你PC上要装的软件少一半!
- Python项目部署-使用Nginx部署Django项目
- Stars HDU - 1541
- VCS
- c#读sql server数据添加到MySQL数据库
- [日常工作]Oracle新增数据文件的小知识点
- Python的二叉树实现
- [bzoj 4034][HAOI 2015]树上操作
热门文章
- MySQL数据库 字段操作 多表关系(更新中...)
- Elasticsearch快速开始
- GULP入门(一)
- PLSQLDeveloper链接报错 解决办法
- Chrome 地址栏如何设置显示 http/https 和 www
- JAVA面试常见问题之基础篇
- 如何在 Flink 1.9 中使用 Hive?
- 使用jquery封装一个可以复用的提示框
- linux查看现在在运行的进程 $ pstree -a$ ps aux
- select2 如何自定义提示信息-布布扣-bubuko.com