2021/06/21

    [LeetCode] Dynamic Programming

    DP Easy문제들을 풀어보았다. 자세한 설명들은 주석에 달아두었다. easy부터 시작해서 감을 익혀 나가야겠다. 1. Best Time to Buy and Sell Stock Point 사고 파는 이윤을 최대로 구입가를 최저로 class Solution { func maxProfit(_ prices: [Int]) -> Int { // 현재 최대 수익은 0 var maxProfits = 0 // 현재 최소 구입가는 prices[0] var buy = prices[0] // price를 돌며 for i in 1.. [Int] { // 1의 갯수를 세줌 for i in 0...n { ans.append(String(i, radix: 2).filter {$0 == "1"}.count) } return ans ..