Swift Solution beats 100%
swift\nclass ExamRoom {\n    var capacity = 0\n    var seats = [Int]()\n\n    init(_ N: Int) {\n        capacity = N\n    }\n    \n    func seat() -> Int {\n   
```swift\nclass ExamRoom {\n    var capacity = 0\n    var seats = [Int]()\n\n    init(_ N: Int) {\n        capacity = N\n    }\n    \n    func seat() -> Int {\n        if seats.count == 0 {\n            seats.append(0)\n            return 0\n        } else if seats.count == capacity {\n            return -1\n        } else {\n            var idx = 0\n            var pos = 0\n            var lastGap = seats[0]\n            for i in 0..<seats.count-1 {\n                let currentGap = (seats[i+1] - seats[i])/2\n                if currentGap > lastGap {\n                    idx = i + 1\n                    pos = seats[i] + currentGap\n                    lastGap = currentGap\n                }\n            }\n\t\t\t\n            if capacity - 1 - seats[seats.count-1] > lastGap {\n                pos = capacity - 1\n                seats.append(pos)\n            } else {\n                seats.insert(pos, at: idx)\n            }\n           \n            return pos\n        }\n    }\n    \n    func leave(_ p: Int) {\n        for i in 0..<seats.count {\n            if seats[i] == p {\n                seats.remove(at: i)\n                break\n            }\n        }\n    }\n}\n```\nMore Swift solutions: https://github.com/twho/LeetCode-Swift
[]