[LeetCode] 416. Partition Equal Subset Sum (C++)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionGiven an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise. Problem ExampleExample 1:Input: nums = [1,5,11,5]Output: trueExplanation: The array can be partitioned as [1, 5, 5] and [11].Example 2:Input: nums = [1,2,3,5]Output: falseExplanation: The array cannot..
[LeetCode] 2140. Solving Questions With Brainpower (Python)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionYou are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri]. The array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you pointsi points but you will be unable to solve ea..
[알고리즘] LCS(Longest Common Subsequence) 알고리즘
·
알고리즘/알고리즘
이번 글에서는 `LCS(Longest Common Subsequence)` 알고리즘에 대해 정리하려고한다. Longest Common Substring도 있지만 이번 글에서는 `Longest Common Subsequence`만 다룰 예정이다. 먼저, `LCS(Longest Common Subsequence)`가 무엇인지 알아보자 What is LCS(Longest Common Subsequence)?`LCS(Longest Common Subsequence)`란 다음과 같다. 두 개의 문자열에서 순서를 유지하면서 일부 문자를 선택해 만들 수 있는 가장 긴 공통 부분 수열  예를 들어, 다음과 같은 문자열이 있다고 가정해보자 String A: ACDBEString B: ABCDE 이 두 문자열의 `LCS`..
[알고리즘] 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)`를 통해 계속 큰 값으로 갱신..