File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Solutions/0067-add-binary Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 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 >  ; </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 >  ; </p >
12+ <p ><strong >Constraints:</strong ></p >
13+
14+ <ul >
15+ <li><code>1 <= a.length, b.length <= 10<sup>4</sup></code></li>
16+ <li><code>a</code> and <code>b</code> consist only of <code>'0'</code> or <code>'1'</code> characters.</li>
17+ <li>Each string does not contain leading zeros except for the zero itself.</li>
18+ </ul >
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def addBinary (self , a : str , b : str ) -> str :
3+ return bin (int (a , 2 ) + int (b , 2 ))[2 :]
You can’t perform that action at this time.
0 commit comments