반응형
SMALL
카데인의 알고리즘
각 수를 더했을 때 가장 큰수가 나오는 연속된 부분을 찾는 알고리즘(maxSubArray)
const maxSubArray = nums => {
let max = nums[0];
let current = Math.max(max, 0);
for (let i = 1; i < nums.length; i += 1) {
current += nums[i];
max = Math.max(max, current);
current = Math.max(current, 0);
}
return max;
};
반응형
LIST
'Coding Interview' 카테고리의 다른 글
[LeetCode] DP, String - 5. Longest Palindromic Substring (0) | 2022.10.03 |
---|---|
[LeetCode] DP - 53. Maximum Subarray (0) | 2022.10.01 |
[LeetCode] DP - 42. Trapping Rain Water (0) | 2022.10.01 |
[LeetCode] BFS - 102. Binary Tree Level Order Traversal (0) | 2022.09.30 |
[기타] 코딩테스트에 활용되는 수학 이론 (1) | 2022.09.30 |