216-Combination-Sum-Iii

Sat 17 May 2025

https://leetcode.com/problems/combination-sum-iii

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

    def dfs(k: int, n: int, s: int, path: List[int]) -> None:
      if k == 0 and n == 0 …

Category: leetcode

Read More

217-Contains-Duplicate

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def containsDuplicate(self, nums: List[int]) -> bool:
    return len(nums) != len(set(nums))
new Solution().containsDuplicate()

Score: 5

Category: leetcode

Read More

218-The-Skyline-Problem

Sat 17 May 2025

https://leetcode.com/problems/the-skyline-problem

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:
    n = len(buildings)
    if n == 0:
      return []
    if n == 1:
      left, right, height = buildings[0]
      return [[left, height], [right …

Category: leetcode

Read More

219-Contains-Duplicate-Ii

Sat 17 May 2025

https://leetcode.com/problems/contains-duplicate-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
    seen = set()

    for i, num in enumerate(nums):
      if i > k:
        seen.remove(nums[i - k - 1])
      if num in …

Category: leetcode

Read More

22-Generate-Parentheses

Sat 17 May 2025

https://leetcode.com/problems/generate-parentheses

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

    def dfs(l: int, r: int, s: str) -> None:
      if l == 0 and r == 0:
        ans.append(s)
      if l > 0:
        dfs(l - 1 …

Category: leetcode

Read More

221-Maximal-Square

Sat 17 May 2025

https://leetcode.com/problems/maximal-square

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maximalSquare(self, matrix: List[List[str]]) -> int:
    m = len(matrix)
    n = len(matrix[0])
    dp = [[0] * n for _ in range(m)]
    maxLength = 0

    for i in range …

Category: leetcode

Read More

222-Count-Complete-Tree-Nodes

Sat 17 May 2025

https://leetcode.com/problems/count-complete-tree-nodes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countNodes(self, root: Optional[TreeNode]) -> int:
    if not root:
      return 0
    return 1 + self.countNodes(root.left) + self.countNodes(root.right)
new Solution().countNodes()

Score: 5

Category: leetcode

Read More

223-Rectangle-Area

Sat 17 May 2025

https://leetcode.com/problems/rectangle-area

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def computeArea(self, A: int, B: int, C: int, D: int, E: int, F: int, G: int, H: int) -> int:
    x = min(C, G) - max(A, E) if max …

Category: leetcode

Read More

224-Basic-Calculator

Sat 17 May 2025

https://leetcode.com/problems/basic-calculator

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def calculate(self, s: str) -> int:
    ans = 0
    num = 0
    sign = 1
    stack = [sign]  # stack[-1]: current env's sign

    for c in s:
      if c.isdigit():
        num = num …

Category: leetcode

Read More

226-Invert-Binary-Tree

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
    if not root:
      return None

    left = root.left
    right = root.right
    root.left = self.invertTree(right)
    root.right = self.invertTree(left …

Category: leetcode

Read More
Page 17 of 77

« Prev Next »