11-Macd
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct 4 2024, 13:27:36) [GCC 11.2.0]'
print(pyu.ps2("requests"))
import yfinance as yf
import pandas as pd
import matplotlib.pyplot …
Read More
110-Balanced-Binary-Tree
https://leetcode.com/problems/balanced-binary-tree
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def isBalanced(self, root: Optional[TreeNode]) -> bool:
if not root:
return True
def maxDepth(root: Optional[TreeNode]) -> int:
if not root:
return 0
return 1 + max(maxDepth(root.left …
Read More
111-Minimum-Depth-Of-Binary-Tree
https://leetcode.com/problems/minimum-depth-of-binary-tree
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def minDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
if not root.left:
return self.minDepth(root.right) + 1
if not root.right:
return self.minDepth …
Read More
112-Path-Sum
https://leetcode.com/problems/path-sum
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def hasPathSum(self, root: TreeNode, summ: int) -> bool:
if not root:
return False
if root.val == summ and not root.left and not root.right:
return True
return self …
Read More
113-Path-Sum-Ii
https://leetcode.com/problems/path-sum-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def pathSum(self, root: TreeNode, summ: int) -> List[List[int]]:
ans = []
def dfs(root: TreeNode, summ: int, path: List[int]) -> None:
if not root:
return
if root.val == summ …
Read More
114-Flatten-Binary-Tree-To-Linked-List
https://leetcode.com/problems/flatten-binary-tree-to-linked-list
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def flatten(self, root: Optional[TreeNode]) -> None:
if not root:
return
self.flatten(root.left)
self.flatten(root.right)
left = root.left # Flattened left
right = root.right # Flattened right …
Read More
115-Distinct-Subsequences
https://leetcode.com/problems/distinct-subsequences
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def numDistinct(self, s: str, t: str) -> int:
m = len(s)
n = len(t)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(m …
Read More
116-Populating-Next-Right-Pointers-In-Each-Node
https://leetcode.com/problems/populating-next-right-pointers-in-each-node
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def connect(self, root: 'Optional[Node]') -> 'Optional[Node]':
if not root:
return None
def connectTwoNodes(p, q) -> None:
if not p:
return
p.next = q
connectTwoNodes(p.left, p …
Read More
117-Populating-Next-Right-Pointers-In-Each-Node-Ii
https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def connect(self, root: 'Node') -> 'Node':
node = root # The node just above current needling
while node:
dummy = Node(0) # Dummy node before needling
# Needle children of node
needle = dummy …
Read More
118-Pascals-Triangle
https://leetcode.com/problems/pascals-triangle
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
ans = []
for i in range(numRows):
ans.append([1] * (i + 1))
for i in range(2, numRows):
for j in range …
Read More