You are viewing a single comment's thread. Return to all comments →
Swift implementation following amoreno_ing:
func minimumBribes(queue: [Int]) -> Void { var reference = Array(1...queue.count) var bribes = 0 for i in 0..<queue.count { if queue[i] == reference[i] { continue } reference.swapAt(i, i+1) if queue[i] == reference[i] { bribes += 1 continue } reference.swapAt(i, i+2) if queue[i] == reference[i] { bribes += 2 continue } return print("Too chaotic") } print(bribes) }
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
Swift implementation following amoreno_ing: