# [67] 二进制求和 简单

# 题解

/*
 * @lc app=leetcode.cn id=67 lang=javascript
 *
 * [67] 二进制求和
 *
 * https://leetcode-cn.com/problems/add-binary/description/
 *
 * algorithms
 * Easy (49.36%)
 * Likes:    220
 * Dislikes: 0
 * Total Accepted:    31.5K
 * Total Submissions: 63.6K
 * Testcase Example:  '"11"\n"1"'
 *
 * 给定两个二进制字符串,返回他们的和(用二进制表示)。
 *
 * 输入为非空字符串且只包含数字 1 和 0。
 *
 * 示例 1:
 *
 * 输入: a = "11", b = "1"
 * 输出: "100"
 *
 * 示例 2:
 *
 * 输入: a = "1010", b = "1011"
 * 输出: "10101"
 *
 */
/**
 * @param {string} a
 * @param {string} b
 * @return {string}
 */
var addBinary = function(a, b) {
  const A = parseInt(a, 2);
  const B = parseInt(b, 2);

  const sum = A + B;

  return sum.toString(2);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43