-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path67.add-binary.jl
57 lines (50 loc) · 962 Bytes
/
67.add-binary.jl
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# ---
# title: 67. Add Binary
# id: problem67
# author: Tian Jun
# date: 2020-10-31
# difficulty: Easy
# categories: Math, String
# link: <https://leetcode.com/problems/add-binary/description/>
# hidden: true
# ---
#
# 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"
#
#
#
#
# **Constraints:**
#
# * `1 <= a.length, b.length <= 104`
# * `a` and `b` consist only of `'0'` or `'1'` characters.
# * Each string does not contain leading zeros except for the zero itself.
#
#
## @lc code=start
using LeetCode
function add_binary(a::String, b::String)
num1 = parse(Int64, a; base=2)
num2 = parse(Int64, b; base=2)
sum = num1 + num2
return string(sum, base=2)
end
## add your code here:
## @lc code=end