原题链接

思路:

用一个数保存进制,从后往前不断pop出两个数字和进制数相加,放入返回值中。

var addBinary = function(a, b) {
var arrA = a.split('');
var arrB = b.split(''); var len = Math.max(a.length, b.length), c = 0, result = '';
while(len-- > 0 || c > 0) {
let va = arrA.pop();
let vb = arrB.pop();
if(va) c += parseInt(va);
if(vb) c += parseInt(vb);
result = (c % 2) + result;
c = c > 1 ? 1 : 0;
}
return result;
};

[leetcode] 67. Add Binary (easy)的更多相关文章

  1. LeetCode 67. Add Binary【个位补0,不必对齐】【easy】

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  2. [leetcode]67. Add Binary 二进制加法

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  3. LeetCode 67. Add Binary (二进制相加)

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

  4. [LeetCode] 67. Add Binary 二进制数相加

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  5. LeetCode 67. Add Binary

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

  6. Java [Leetcode 67]Add Binary

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

  7. (String) leetcode 67. Add Binary

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  8. LeetCode - 67. Add Binary(4ms)

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  9. leetcode 67. Add Binary (高精度加法)

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

随机推荐

  1. MinGW和MSYS区别和关系以及MinGW&MSYS在Win7中安装并编译x264

    http://blog.csdn.net/freeape/article/details/50555003

  2. 百度网盘背后的存储系统atlas

    原文  http://www.bitstech.net/2015/07/25/baidu-atlas/   百度网盘免费提供2TB存储, 它的存储量一定是惊人的, 支持它的存储系统atlas也是相当不 ...

  3. 做个知识回顾目录,打算每日更新一下ios的基础知识

    一.基础技能列表:   01 面向对象特性       类与方法封装       通过继承扩展类       抽象类与方法覆盖       多态.动态类型和动态绑定       分类和协议       ...

  4. Md2All:好用的markdown文件转换工具,文章迁移微信公众号的利器

    目录 简介 使用体验 极速上手 更多功能 总结 简介 markdown以简单的语法和强大的功能,征服了无数技术创作者,几乎主流的技术博客网站都开始支持markdown语言撰写博客.但是微信公众号的文章 ...

  5. Linux实战型企业运维工程师试题

    1.如何通过Linux配置一个局域网或者IDC机房上网网关,请给出步骤及命令?答:上网网关配置(1)开启内核转发:sed -i 's#net.ipv4.ip_forward = 0#net.ipv4. ...

  6. Android自动化测试探索(三)Android SDK tools安装、aapt配置以及使用aapt获取apk包名

    Android SDK tools安装 下载连接: https://www.androiddevtools.cn 找到对应mac的版本下载安装即可 AAPT配置 #1. 进入根目录 cd ~ #2. ...

  7. 《linux内核设计与实现》阅读笔记-进程与调度

      一.进程 process: executing program code(text section) data section containing global variables open f ...

  8. __file__、__name__、__dict__方法整理

    本文主要介绍__file__.__name__.__dict__三个方法的作用. #01 __file__:打印当前文件的位置. # import os # print(__file__) # 在py ...

  9. WebFlux 集成 Thymeleaf 、 Mongodb 实践 - Spring Boot(六)

    这是泥瓦匠的第105篇原创 文章工程: JDK 1.8 Maven 3.5.2 Spring Boot 2.1.3.RELEASE 工程名:springboot-webflux-5-thymeleaf ...

  10. RestTemplate使用不当引发的问题分析

    背景 系统: SpringBoot开发的Web应用: ORM: JPA(Hibernate) 接口功能简述: 根据实体类ID到数据库中查询实体信息,然后使用RestTemplate调用外部系统接口获取 ...