적당한 고통은 희열이다

- 댄 브라운 '다빈치 코드' 중에서

반응형

Algorithm/LeetCode 15

[Swift 알고리즘] LeetCode 53. Maximum Subarray

× Dynamic Programming, Divide and Conquer | Medium LeetCode 53. Maximum Subarray for문 중첩해서 돌려서 O(n^2) 으로 풀었더니 당연히 시간초과 뜸,, Time Limit Exceeded 더보기 subarray 하나씩 더해가면서 값 저장하는 방식,, let solution = Solution() print(solution.maxSubArray([-2,1,-3,4,-1,2,1,-5,4])) //6 print(solution.maxSubArray([-2])) //-2 print(solution.maxSubArray([1])) //1 class Solution { func maxSubArray(_ nums: [Int]) -> Int { if ..

Algorithm/LeetCode 2023.04.03

[Swift 알고리즘] LeetCode 2457. Minimum Addition to Make Integer Beautiful

× 그리디? Medium You are given two positive integers n and target. An integer is considered beautiful if the sum of its digits is less than or equal to target. Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful. Constraints: - 1 Int { var array = String(n).map({ Int(String($0))! }) var sum = array.r..

Algorithm/LeetCode 2023.03.10
728x90
반응형