Skip to content

Commit 806de28

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 17.6 MB (91.64%)
1 parent 69af5f5 commit 806de28

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<p>Given two binary strings <code>a</code> and <code>b</code>, return <em>their sum as a binary string</em>.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
<pre><strong>Input:</strong> a = "11", b = "1"
6+
<strong>Output:</strong> "100"
7+
</pre><p><strong class="example">Example 2:</strong></p>
8+
<pre><strong>Input:</strong> a = "1010", b = "1011"
9+
<strong>Output:</strong> "10101"
10+
</pre>
11+
<p>&nbsp;</p>
12+
<p><strong>Constraints:</strong></p>
13+
14+
<ul>
15+
<li><code>1 &lt;= a.length, b.length &lt;= 10<sup>4</sup></code></li>
16+
<li><code>a</code> and <code>b</code> consist&nbsp;only of <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code> characters.</li>
17+
<li>Each string does not contain leading zeros except for the zero itself.</li>
18+
</ul>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def addBinary(self, a: str, b: str) -> str:
3+
return bin(int(a, 2) + int(b, 2))[2:]

0 commit comments

Comments
 (0)