This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def maxProfit(self, prices: List[int]) -> int: | |
buy1,buy2 = -sys.maxsize,-sys.maxsize | |
profit1,profit2 = 0,0 | |
for price in prices: | |
buy1 = max(buy1, -price) | |
profit1 = max(profit1, buy1 + price) | |
buy2 = max(buy2, profit1 - price) | |
profit2 = max(profit2, buy2 + price) | |
return profit2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def wordBreak(self, s: str, wordDict: List[str]) -> bool: | |
def word_break(s,wordDict,begin,memo): | |
if len(s) == begin: | |
return True | |
if memo[begin]: | |
print('check') | |
return memo[begin] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def connect(self, root): | |
""" | |
:type root: TreeLinkNode | |
:rtype: nothing | |
""" | |
if not root: | |
return | |
pre = root | |
while root.left: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def hasPathSum(self, root: TreeNode, suma: int) -> bool: | |
def findpath(root,groupint): | |
if root: | |
groupint.append(root.val) | |
if not root.right and not root.left: | |
if sum(groupint) == suma: | |
print('check')<----print 了两次,说明第一次并没有 return True 出 method | |
return True <----请问这里为什么 return 不出去? | |
groupint.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def hasPathSum(self, root: TreeNode, suma: int) -> bool: | |
def findpath(root,groupint): | |
if root: | |
groupint.append(root.val) | |
if not root.right and not root.left: | |
if sum(groupint) == suma: | |
self.res = True | |
groupint.pop() | |
else: |