We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 551fd84 commit b1d3e60Copy full SHA for b1d3e60
maximum-product-subarray/Leo.py
@@ -0,0 +1,14 @@
1
+class Solution:
2
+ def maxProduct(self, nums: List[int]) -> int:
3
+ curMax, curMin = 1, 1
4
+ res = nums[0]
5
+
6
+ for n in nums:
7
+ vals = (n, n * curMax, n * curMin)
8
+ curMax, curMin = max(vals), min(vals)
9
10
+ res = max(res, curMax)
11
12
+ return res
13
14
+ ## TC: O(n), SC: O(1)
word-break/Leo.py
@@ -0,0 +1,13 @@
+ def wordBreak(self, s: str, wordDict: List[str]) -> bool:
+ dp = [True] + [False] * len(s)
+ for i in range(1, len(s) + 1):
+ for w in wordDict:
+ if i - len(w) >= 0 and dp[i - len(w)] and s[:i].endswith(w):
+ dp[i] = True
+ return dp[-1]
+ ## TC: O(len(str) * len(wordDict) * len(avg(wordDict[n])))
+ ## SC: O(n)
0 commit comments