原题链接

思路:

用一个数保存进制,从后往前不断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. 什么水平算精通C++ Builder?

    主 题:   大家讨论一下什么水平算精通C++ Builder?(我这样算什么,马上要毕业了,不知道如何评价自己)         //C++ builder 使用时间3年 熟悉VCL源代码 开发过3 ...

  2. easyui在IE中: SCRIPT1003: 缺少 ':'

  3. Oracle 裁掉北京研发团队,相应职位撤回美国(收购了NetSuite,LogFire,Dyn)

    根据中国日报报道,2017年1月14日上午9点09分,甲骨文北京研发团队的同事收到了来自BU老大的一封邮件.邮件上提及,由于市场变化,甲骨文开始整合各研发中心资源公司在云计算方向发力,文末单独提出了甲 ...

  4. QImage的浅拷贝与深拷贝

     首先简单说说什么是浅拷贝和深拷贝:浅拷贝就比如像引用类型,而深拷贝就比如值类型,即浅拷贝是共用一块内存的,而深拷贝是复制一份内容.   我们再来看看QImage类的几个构造函数: // 浅拷贝 QI ...

  5. Mac OS下terminal的快捷键

    时隔2年又开始使用Mac OS系统,之前的很多快捷键和常用的命令都忘记了,使用起来确实不方便,效率也低,特别是terminal下,所以对于terminal又找了一下并整理如下,希望对后来的同学也有用: ...

  6. 使窗体拥有透明效果的API

    一.背景FlashGet的透明效果大家羡慕吧.传统的Windows应用程序想实现半透明效果,一般来说需要处理自己的窗口的WM_Paint消息窗口,很麻烦.现在好了,SetLayeredWindowAt ...

  7. C#基础原理拾遗——引用类型的值传递和引用传递

    以前写博客不深动,只搭个架子,像做笔记,没有自己的思考,也没什么人来看.这个毛病得改,就从这一篇开始- 最近准备面试,深感基础之重要,奈何我不是计算机科班出身,基础方面有些捉襟见肘.短期怎么补?做面实 ...

  8. linux dll hell--链接库real name, soname, link name

    DLL hell 是指 Windows 系统上动态库的新版本覆盖旧版本,且新版本不能兼容旧版本的问题. 例如:装新软件,但原有的软件运行不起来了.   Linux 系统下也同样面临着和 Windows ...

  9. js中prototype与__proto__区别

    proto(隐式原型)与prototype(显式原型) 显式原型 explicit prototype property:每一个函数在创建之后都会拥有一个名为prototype的属性,这个属性指向函数 ...

  10. SqlServer执行计划

    MSSQLSERVER执行计划详解 * from ServiceInvoke; --创建时间聚集索引扫描 * from AdoLog; --主键ID聚集索引扫描 --2.根据聚集索引排序-性能提升 - ...