【leetcode】67-AddBinary
2024-10-14 19:08:21
problem
code
class Solution {
public:
string addBinary(string a, string b) {
string res;
int i = a.size()-;
int j = b.size()-;
int carry = ;
while(carry || i >= || j>=)//
{
carry += (i>=) ? a[i--]-'' : ;//
carry += (j>=) ? b[j--]-'' : ;
res = char(carry% + '') + res;//??
carry /= ;
}
return res;
}
};
注意
1.每个字符串中的每个字符对应的数字进行数字运算,且最后的结果是字符串;
2.int型和字符类型之间的转换;
3.string类型可以直接使用符号'+'进行字符串的连接;
4.进位和余数的运算;
参考
完
最新文章
- nodejs+easyui(抽奖活动后台)增删改查
- html4,xhtml,html5发展历史
- cloudera manager安装spark后使用spark shell编写基于scala的world count
- JavaScript内置对象之数组
- java script 确认框
- equals()和hashcode()
- Hadoop2.2.0 自动切换HA环境搭建
- php 多维数组如何用foreach遍历修改其中的一个值
- thymeleaf模板引擎入门
- JS使用循环按指定倍数分割数组组成新的数组的方法
- PGM:图模型学习概述
- 前端——jQuery
- centos7.4 linux 指令
- 变量类型-List
- keepalived vip 没有生成或者生成了ping不通?
- AJAX从入门到放弃(二)
- python 闯关之路四(下)(并发编程与数据库编程)
- 【BZOJ4873】[六省联考2017]寿司餐厅(网络流)
- 包含MIN函数的栈+一个数组实现两个堆栈+两个数组实现MIN栈
- UFT测试本地应用程序登陆小实例(描述性编程)