Update 04_recursive_max.swift

It wasn't working when the array was empty or when it had only one element.
This commit is contained in:
Pablo Paciello
2017-07-06 13:02:11 +02:00
committed by Aditya Bhargava
parent 86785a0659
commit 885c5f8b19

View File

@@ -3,6 +3,8 @@ import Foundation
func max(list : [Int]) -> Int {
if list.count == 2 {
return (list[0] > list[1]) ? list[0] : list[1]
} else if list.count < 2 {
return list.first ?? 0
}
var tempArray = list
tempArray.remove(at: 0)