Skip to content

Commit 885c5f8

Browse files
PPacieegonSchiele
authored andcommitted
Update 04_recursive_max.swift
It wasn't working when the array was empty or when it had only one element.
1 parent 86785a0 commit 885c5f8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

04_quicksort/swift/04_recursive_max.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Foundation
33
func max(list : [Int]) -> Int {
44
if list.count == 2 {
55
return (list[0] > list[1]) ? list[0] : list[1]
6+
} else if list.count < 2 {
7+
return list.first ?? 0
68
}
79
var tempArray = list
810
tempArray.remove(at: 0)

0 commit comments

Comments
 (0)