Here, We see Add Binary LeetCode Solution. This Leetcode problem is done in many programming languages like C++, Java, JavaScript, Python, etc. with different approaches.

# List of all LeetCode Solution

## Problem Statement

Given two binary strings `a` and `b`, return their sum as a binary string.

```Example 1:

Input: a = "11", b = "1"
Output: "100"

Example 2:

Input: a = "1010", b = "1011"
Output: "10101"
```

## Add Binary Leetcode Solution C++

``````class Solution {
public:
string addBinary(string a, string b) {
if (a.size() < b.size())
swap(a, b);
int i = a.size(), j = b.size();
while (i--) {
if (j) a[i] += b[--j] & 1;
if (a[i] > '1') {
a[i] -= 2;
if (i) a[i-1]++; else a = '1' + a;
}
}
return a;
}
};```Code language: PHP (php)```

## Add Binary Leetcode Solution Java

``````class Solution {
public String addBinary(String a, String b) {
StringBuilder sb = new StringBuilder();
int i = a.length() - 1, j = b.length() -1, carry = 0;
while (i >= 0 || j >= 0) {
int sum = carry;
if (j >= 0) sum += b.charAt(j--) - '0';
if (i >= 0) sum += a.charAt(i--) - '0';
sb.append(sum % 2);
carry = sum / 2;
}
if (carry != 0) sb.append(carry);
return sb.reverse().toString();
}
}```Code language: JavaScript (javascript)```

## Add Binary Leetcode Solution JavaScript

``````var addBinary = function(a, b) {
return (BigInt("0b"+a) + BigInt("0b"+b)).toString(2);
};    ```Code language: JavaScript (javascript)```

``````class Solution(object):
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://totheinnovation.com/add-binary-leetcode-solution/", "fetch_time": 1714000866000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2024-18/segments/1712296819971.86/warc/CC-MAIN-20240424205851-20240424235851-00577.warc.gz", "warc_record_offset": 522458476, "warc_record_length": 33425, "token_count": 452, "char_count": 1449, "score": 3.84375, "int_score": 4, "crawl": "CC-MAIN-2024-18", "snapshot_type": "latest", "language": "en", "language_score": 0.40979039669036865, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00021-of-00064.parquet"}