-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsolution.swift
More file actions
30 lines (28 loc) · 917 Bytes
/
solution.swift
File metadata and controls
30 lines (28 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Foundation
func solution(_ A:inout [Int]) -> Int{
var result = 1
let filteredIntSet = Set<Int>(A.filter{$0 > 0})
while filteredIntSet.contains(result) {
result += 1
}
return result
}
let file: FileHandle? = FileHandle(forReadingAtPath: "input-02.txt")
if let file = file {
// Read all the data
let data = file.readDataToEndOfFile()
// Close the file
file.closeFile()
// Convert our data to string
let str = String(data: data, encoding: .utf8)!
let lines:[String] = str.characters.split{$0 == "\n"}.map(String.init)
var arr:[Int] = lines[0].components(separatedBy: " ").map{ Int($0)! }
let startTime = Date()
let result = solution(&arr)
let endTime = Date()
print(result)
// Milli Seconds
print((endTime.timeIntervalSince1970 - startTime.timeIntervalSince1970) * 1000)
} else {
print("File was not loaded")
}