다이나믹프로그래밍26 [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. [leetcode 647] Palindromic Substrings palindromic substring을 세는 문제 Example 1: Input: "abc" Output: 3 Explanation: Three palindromic strings: "a", "b", "c". Example 2: Input: "aaa" Output: 6 Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa". Note: The input string length won't exceed 1000. 다행히 문자열이 1000을 안넘어서 그런지 for문 돌려도 통과했다...하지만 몹시 느린 것이 사실 class Solution { public: int countSubstrings(string s) { int result =.. 2020. 10. 6. 이전 1 ··· 4 5 6 7 다음