1087-Brace-Expansion

Sat 17 May 2025

https://leetcode.com/problems/brace-expansion

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def expand(self, s: str) -> List[str]:
    ans = []

    def dfs(i: int, path: List[str]) -> None:
      if i == len(s):
        ans.append(''.join(path))
        return
      if s[i] == '{':
        nextRightBraceIndex …

Category: leetcode

Read More

1088-Confusing-Number-Ii

Sat 17 May 2025

https://leetcode.com/problems/confusing-number-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def confusingNumberII(self, n: int) -> int:
    digitToRotated = [(0, 0), (1, 1), (6, 9), (8, 8), (9, 6)]

    def dfs(num: int, rotatedNum: int, unit: int) -> int:
      ans = 0 if …

Category: leetcode

Read More

1089-Duplicate-Zeros

Sat 17 May 2025

https://leetcode.com/problems/duplicate-zeros

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def duplicateZeros(self, arr: List[int]) -> None:
    zeros = arr.count(0)
    i = len(arr) - 1
    j = len(arr) + zeros - 1

    while i < j:
      if j < len(arr):
        arr[j …

Category: leetcode

Read More

109-Convert-Sorted-List-To-Binary-Search-Tree

Sat 17 May 2025

https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortedListToBST(self, head: ListNode) -> TreeNode:
    def findMid(head: ListNode) -> ListNode:
      prev = None
      slow = head
      fast = head

      while fast and fast.next:
        prev = slow
        slow = slow.next
        fast = fast …

Category: leetcode

Read More

11-Container-With-Most-Water

Sat 17 May 2025

https://leetcode.com/problems/container-with-most-water

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxArea(self, height: List[int]) -> int:
    ans = 0
    l = 0
    r = len(height) - 1

    while l < r:
      minHeight = min(height[l], height[r])
      ans = max(ans, minHeight * (r …

Category: leetcode

Read More

110-Balanced-Binary-Tree

Sat 17 May 2025

https://leetcode.com/problems/balanced-binary-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

111-Minimum-Depth-Of-Binary-Tree

Sat 17 May 2025

https://leetcode.com/problems/minimum-depth-of-binary-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

112-Path-Sum

Sat 17 May 2025

https://leetcode.com/problems/path-sum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

113-Path-Sum-Ii

Sat 17 May 2025

https://leetcode.com/problems/path-sum-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More

114-Flatten-Binary-Tree-To-Linked-List

Sat 17 May 2025

https://leetcode.com/problems/flatten-binary-tree-to-linked-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
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 …

Category: leetcode

Read More
Page 7 of 77

« Prev Next »