[알고리즘] Maximum Subarray Sum - Kadane's Algorithm (카데인 알고리즘)
·
알고리즘/알고리즘
What is Kadane's Algorithm? `Kadane's Algorithm`은 다음과 같다. 연속 하는 부분 배열의 최대 합을 효율적으로 찾는 알고리즘  즉, 주어진 배열에서 연속된 요소들의 부분 배열 중 가장 큰 합을 가지는 부분 배열을 찾는 알고리즘이다. 이 알고리즘은 `동적 계획법(Dynamic Programming, DP)`을 활용하여 문제를 해결하며 `O(N)`의 시간 복잡도를 갖는다.  Kadane's Algorithm 동작 원리`Kadane's Algorithm`의 동작 원리는 다음과 같다. 현재 위치까지의 최대 부분합을 저장하는 `local_max` 변수를 유지한다.`local_max`는 `max(nums[i], nums[i] + local_max)`를 통해 계속 큰 값으로 갱신..
[LeetCode] 1749. Maximum Absolute Sum of Any Subarray (Python)
·
알고리즘/LeetCode
난이도: MediumProblem Description You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr). Return the maximum absolute sum of any (possibly empty) subarray of nums. Note that abs(x) is defined as follows:If x is a negative integer, then abs(x) = -x.If x is a non-negative integer, then abs(x) = x. Probl..