LeetCode – 67. Add Binary

//Test case:
// a: "", b: ""
// a: "", b: "1"
// a: "1", b: "1"
// a: "1", b: "11"

   func addBinary(_ a: String, _ b: String) -> String {
        if a.isEmpty { return b }
        else if b.isEmpty { return a}

        var carry = 0
        var arr1 = Array(a)
        var arr2 = Array(b)
        var index1 = arr1.count - 1
        var index2 = arr2.count - 1
        var result = ""
        while index1 >= 0 || index2 >= 0 {
        	let val1 = index1 >= 0 ? Int(String(arr1[index1]))! : 0
        	let val2 = index2 >= 0 ? Int(String(arr2[index2]))! : 0
        	let sum = val1 + val2 + carry
        	carry = sum / 2
        	let partialResult = String(sum % 2)
        	result = partialResult + result
        	index1 -= 1
        	index2 -= 1
        }
        if carry > 0 {
        	result = "\(carry)" + result
        }
        return result
   }

Ref: https://leetcode.com/problems/add-binary/