Created
January 4, 2020 13:03
-
-
Save Nirma/5f5a947fbca7020da7a7fe5ad4fee077 to your computer and use it in GitHub Desktop.
Top Down Rod Cutting DP Example in Swift (Inefficient Version)
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
func maxProfitRodCut(prices: [Int], length: Int) -> Int { | |
if length <= 0 { | |
return 0 | |
} | |
var currentMax = Int.min | |
for index in (1...length) { | |
currentMax = max(currentMax, prices[index - 1] + maxProfitRodCut(prices: prices, length: length - index)) | |
} | |
return currentMax | |
} | |
maxProfitRodCut(prices: [1,6,3,6], length: 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment