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;

【leetcode】67-AddBinary的更多相关文章

  1. 【LeetCode】67. Add Binary 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BigInteger类 模拟加法 日期 题目地址:h ...

  2. 【LeetCode】67. Add Binary

    题目: Given two binary strings, return their sum (also a binary string). For example,a = "11" ...

  3. 【LEETCODE】67、分治递归,medium&hard级别,题目:215、312

    我被这些题整哭了,你呢??? 日了狗啊...... 好难啊.... 按照这个样子搞,不用找工作了,回家放牛去....... package y2019.Algorithm.divideandconqu ...

  4. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  5. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  7. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  8. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  9. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

  10. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

随机推荐

  1. zzw原创_LIKE与regexp_like中的_及转义符

    1.select table_name from user_tables  where table_name like 'MENU%';查出以下表MENUMENUGGG_131MENU_132MENU ...

  2. iOS的Cookie存取

    当前一些公司为了快速出一款app,很多时候采用UINavigationController+WebView或者NavigationController+UITabbarVC+WebView的方式,这样 ...

  3. ftp/sftp定时自动上传文件脚本(CentOS)

    1.ftp自动上传文件脚本 #!/bin/bash ftp -n<<! open 192.168.220.129 user ls toor binary hash cd /path/to/ ...

  4. URL加载jar

    // !/test.xml 是表示jar中的test.xml文件 final URL jarUrl = new URL("jar:file:/C:/proj/parser/jar/parse ...

  5. e2e 测试(1)

    距离上一随笔,已经有一个月没有没写.到今天,刚刚好好,是学习e2e测试的一个月.今天有点时间可以总结一下这个月来的收获. 1.搭建e2e的测试环境 我是使用 Vue 构建项目,所以我也是通过Vue-c ...

  6. Javaconfig形式配置Dubbo多注册中心

    多注册中心,一般用不到,但是某些情况下的确能解决不少问题,可以将某些dubbo服务注册到2套dubbo系统中,实现服务在2套系统间的共用. 网上的配置说明很多,但包括dubbo官方说明文档都是以xml ...

  7. WPF 基于Adorner实现类似Popup效果

    1.  什么是Adorner 装饰器是一种特殊类型的FrameworkElement,可用来向用户提供可视提示. 装饰器有很多用途,可用来向元素添加功能句柄,或者提供有关某个控件的状态信息. 2.  ...

  8. DoTween动画中的几种函数。

    1.transform.DOLocalMoveX(200, 1).From(true); 动画默认是从当前位置沿着X轴移动到x=200的位置. 加上Form变为从X=200的位置移动到当前位置,fro ...

  9. javascript es6系列教程 - 不定参数与展开运算符(...)

    三个点(...)在es6中,有两个含义: 用在形参中, 表示传递给他的参数集合, 类似于arguments, 叫不定参数. 语法格式:  在形参面前加三个点( ... ) 用在数组前面,可以把数组的值 ...

  10. docker 将正在运行的容器打包为镜像

    将容器打包成镜像 docker commit -a "runoob.com" -m "my apache" 容器名称或id 打包的镜像名称:标签 OPTIONS ...