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
| class Solution { | |
| func myAtoi(_ str: String) -> Int { | |
| var value = 0 | |
| var hasValue = false | |
| var isNegative = false | |
| let max = (1 << 31) - 1 | |
| let min = -(1 << 31) |
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
| import Foundation | |
| func mult(a: [UInt16], b: [UInt16]) -> [UInt16] { | |
| var c = [UInt16]() | |
| for (i, x) in b.reversed().enumerated() { | |
| var r = UInt16(0) | |
| for (j, y) in a.reversed().enumerated() { | |
| let k = i + j |
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
| struct Matrix: CustomStringConvertible { | |
| private var values = [[Int]]() | |
| private var indices = [[(Int, Int)]]() | |
| private let N: Int | |
| private let M: Int | |
| init(lines: [String]) { | |
| let rows = lines.map({ $0.split(separator: " ", maxSplits: Int.max, omittingEmptySubsequences: true).flatMap({ Int($0) }) }) |
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 absolutePermutation(n: Int, k: Int) -> String { | |
| let r = (1...n) | |
| var tmp = Set<Int>() | |
| var res = "" | |
| for i in r { | |
| var a = i + k | |
| var b = i - k |
NewerOlder