본문 바로가기

전체 글351

[leetcode 322] Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. You may assume that you have an infinite number of each kind of coin. Example 1: Input: coins = [1,2,5], amount = 11 Output: 3 Explanati.. 2020. 10. 7.
[leetcode 338] Counting Bits 주어진 num까지 각각의 숫자를 이진수로 변환시켰을 때 1의 개수를 기록한 배열을 return Example 1: Input: 2 Output: [0,1,1] Example 2: Input: 5 Output: [0,1,1,2,1,2] ex2에서 0부터 5까지 각각을 이진수로 변환 0, 1, 10, 100 ... 그 때 1의 숫자를 세서 배열에 저장한다. 풀이 - dp - dp 치곤 쉬웠다. - 표를 적다보면 규칙이 발견된다. 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 1 2 1 2 2 3 1 2 2 3 2 1)2의 제곱수는 무조건 1이다. 2) 2의제곱수 사이에 있는 수는( 2 2020. 10. 7.
[leetcode 416] Partition Equal Subset Sum Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. Note: Each of the array element will not exceed 100. The array size will not exceed 200. Example 1: Input: [1, 5, 11, 5] Output: true Explanation: The array can be partitioned as [1, 5, 5] and [11]. Example 2: Input: [1, 2, 3, 5].. 2020. 10. 6.
[leetcode 494] Target Sum 문제: 주어진 모든 수 앞에 +나 -를 붙여서 계산한다. 계산값이 S와 동일한 경우를 카운트 Example 1: Input: nums is [1, 1, 1, 1, 1], S is 3. Output: 5 Explanation: -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 There are 5 ways to assign symbols to make the sum of nums be target 3. Constraints: The length of the given array is positive and will not exceed 20. The sum of elements in the given array will no.. 2020. 10. 6.
[c++] accumulate 함수 - 배열 안에 모든 값을 더하는 함수 #include using namespace std int main(void){ vector v; //v 벡터 전체 합: 시작점, 마지막, 처음 시작 값 int sum = accumulate(v.begin(), v.end(), 0); //long long을 쓰려면 long long sum = accumulate(v.begin(), v.end(), 0LL); } 2020. 10. 6.