Created
November 8, 2015 07:34
-
-
Save rjeli/60eff69b5176a1e07646 to your computer and use it in GitHub Desktop.
Hardcore DP
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be
profit (x:xs) = f x 0 xs
for better style points