Skip to content

Commit 18ba34a

Browse files
committed
Add 377
1 parent 2d6636c commit 18ba34a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ https://leetcode.com/jummyegg/
122122
| 362 | Design Hit Counter | Medium | O(1) | O(N) | Design, Premium | | 🔒 |
123123
| 367 | Valid Perfect Square | Easy | O(logN) | O(1) | Math, Binary Search | | |
124124
| 376 | Wiggle Subsequence | Medium | O(N) | O(1) | Greedy, Dynamic Programming | | |
125+
| 377 | Combination Sum IV | Medium | O(T) | O(T) | Dynamic Programming | | |
125126
| 378 | Kth Smallest Element in a Sorted Matrix | Medium | O(N^2logK) | O(K) | Heap, Binary Search | | |
126127
| 380 | Insert Delete GetRandom | Medium | O(1) | O(N) | Array, Hash Table, Design | | |
127128
| 384 | Shuffle an Array | Medium | O(N) | O(N) | | | |
@@ -464,7 +465,7 @@ https://leetcode.com/jummyegg/
464465
| 1758 | Minimum Changes To Make Alternating Binary String | Easy | O(N) | O(1) | Array, Greedy | | |
465466
| 1759 | Count Number of Homogenous Substrings | Medium | O(N) | O(1) | String, Greedy | | |
466467
| 1763 | Longest Nice Substring | Easy | O(NlogN) | O(N) | String | | |
467-
| 1764 | Form Array by Concatenating Subarrays of Another Array | Medium | O(N+M) | O(M) | Array, Greedy | | |
468+
| 1764 | Form Array by Concatenating Subarrays of Another Array | Medium | O(N+M) | O(M) | Array, Greedy | New Algorithm | |
468469
| 1765 | Map of Highest Peak | Medium | O(N\*M) | O(N\*M) | BFS, Graph | | |
469470
| 1768 | Merge Strings Alternately | Easy | O(N) | O(N) | String | | |
470471
| 1769 | Minimum Number of Operations to Move All Balls to Each Box | Medium | O(N) | O(N) | Array, Greedy | | |

src/377.combination-sum-iv.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# @lc app=leetcode id=377 lang=python3
3+
#
4+
# [377] Combination Sum IV
5+
#
6+
7+
# @lc code=start
8+
# TAGS: Dynamic Programming
9+
10+
11+
class Solution:
12+
# 48 ms, 28.27%. Time: O(T). Space: O(T)
13+
def combinationSum4(self, nums: List[int], target: int) -> int:
14+
@cache
15+
def dfs(sofar=0):
16+
if sofar > target:
17+
return 0
18+
if sofar == target:
19+
return 1
20+
return sum(dfs(sofar + n) for n in nums)
21+
return dfs()
22+
# @lc code=end

0 commit comments

Comments
 (0)