Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Created January 22, 2020 13:02
Show Gist options
  • Select an option

  • Save AppleCEO/93951773e86bebb9bf4a3eb9ea1304b5 to your computer and use it in GitHub Desktop.

Select an option

Save AppleCEO/93951773e86bebb9bf4a3eb9ea1304b5 to your computer and use it in GitHub Desktop.
func solution(_ n:Int, _ arr1:[Int], _ arr2:[Int]) -> [String] {
var answer: [String] = Array<String>.init(repeating: "", count: arr1.count)
func pad(string : String, toSize: Int) -> String {
var padded = string
for _ in 0..<(toSize - string.count) {
padded = "0" + padded
}
return padded
}
for stringIndex in 0..<arr1.count {
let binary1 = Array(pad(string: String(arr1[stringIndex], radix: 2), toSize: arr1.count))
let binary2 = Array(pad(string: String(arr2[stringIndex], radix: 2), toSize: arr1.count))
for (charIndex, character) in binary1.enumerated() {
if character == "0" && binary2[charIndex] == "0" {
answer[stringIndex] += " "
} else {
answer[stringIndex] += "#"
}
}
}
return answer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment