problem

AddBinary

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.进位和余数的运算;

参考

1.leetcode_AddBinary;

最新文章

  1. nodejs+easyui(抽奖活动后台)增删改查
  2. html4,xhtml,html5发展历史
  3. cloudera manager安装spark后使用spark shell编写基于scala的world count
  4. JavaScript内置对象之数组
  5. java script 确认框
  6. equals()和hashcode()
  7. Hadoop2.2.0 自动切换HA环境搭建
  8. php 多维数组如何用foreach遍历修改其中的一个值
  9. thymeleaf模板引擎入门
  10. JS使用循环按指定倍数分割数组组成新的数组的方法
  11. PGM:图模型学习概述
  12. 前端——jQuery
  13. centos7.4 linux 指令
  14. 变量类型-List
  15. keepalived vip 没有生成或者生成了ping不通?
  16. AJAX从入门到放弃(二)
  17. python 闯关之路四(下)(并发编程与数据库编程)
  18. 【BZOJ4873】[六省联考2017]寿司餐厅(网络流)
  19. 包含MIN函数的栈+一个数组实现两个堆栈+两个数组实现MIN栈
  20. UFT测试本地应用程序登陆小实例(描述性编程)

热门文章

  1. redis sentinel哨兵模式集群搭建教程
  2. 静态HTML总结
  3. 【框架】用excel管理测试用例需要的参数数据(二)
  4. laravel中文件上传:
  5. learning at command AT+CSQ
  6. learning scala 数组和容器
  7. Python自学笔记-装饰器1(廖雪峰的网站)
  8. Java作业五
  9. BeanUtils出现Java.lang.NoClassDefFoundError解决
  10. 201621123001 《java程序设计》 第3周学习总结