Created
January 22, 2020 13:02
-
-
Save AppleCEO/93951773e86bebb9bf4a3eb9ea1304b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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