This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
profit :: [Int] -> Int | |
profit xs = f (head xs) 0 (tail xs) | |
where | |
f minVal maxDiff [] = maxDiff | |
f minVal maxDiff (x:xs) = f (min minVal x) (max maxDiff (x - minVal)) xs | |
-- O(n) time, O(1) memory |
NewerOlder