127-Word-Ladder

Fri 14 November 2025

https://leetcode.com/problems/word-ladder

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
    wordSet = set(wordList)
    if endWord not in wordSet:
      return 0

    ans = 0
    q = deque([beginWord])

    while q:
      ans …

Category: leetcode

Read More

128-Longest-Consecutive-Sequence

Fri 14 November 2025

https://leetcode.com/problems/longest-consecutive-sequence

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

    for num in nums:
      if num - 1 in seen:
        continue
      length = 0
      while num in seen:
        num …

Category: leetcode

Read More

129-Sum-Root-To-Leaf-Numbers

Fri 14 November 2025

https://leetcode.com/problems/sum-root-to-leaf-numbers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sumNumbers(self, root: Optional[TreeNode]) -> int:
    ans = 0

    def dfs(root: Optional[TreeNode], path: int) -> None:
      nonlocal ans
      if not root:
        return
      if not root.left and not …

Category: leetcode

Read More

13-Commadity-Channel-Index

Fri 14 November 2025
# Created: 20250103
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"))
requests==2.32.3
import yfinance as yf
import pandas as pd
import numpy as …

Category: stockmarket

Read More

13-Roman-To-Integer

Fri 14 November 2025

https://leetcode.com/problems/roman-to-integer

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def romanToInt(self, s: str) -> int:
    ans = 0
    roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50,
             'C': 100, 'D': 500, 'M': 1000}

    for a, b in zip(s …

Category: leetcode

Read More

130-Surrounded-Regions

Fri 14 November 2025

https://leetcode.com/problems/surrounded-regions

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

    m = len(board)
    n = len(board[0])
    dirs = [0, 1, 0, -1, 0]
    q = deque()

    for i …

Category: leetcode

Read More

131-Palindrome-Partitioning

Fri 14 November 2025

https://leetcode.com/problems/palindrome-partitioning

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

    def isPalindrome(s: str) -> bool:
      return s == s[::-1]

    def dfs(s: str, j: int, path: List[str], ans: List …

Category: leetcode

Read More

132-Palindrome-Partitioning-Ii

Fri 14 November 2025

https://leetcode.com/problems/palindrome-partitioning-ii

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

    for i in range(n):
      mini = i
      for j …

Category: leetcode

Read More

133-Clone-Graph

Fri 14 November 2025

https://leetcode.com/problems/clone-graph

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def cloneGraph(self, node: 'Node') -> 'Node':
    if not node:
      return None

    q = deque([node])
    map = {node: Node(node.val)}

    while q:
      u = q.popleft()
      for v in u.neighbors …

Category: leetcode

Read More

134-Gas-Station

Fri 14 November 2025

https://leetcode.com/problems/gas-station

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
    ans = 0
    net = 0
    summ = 0

    for i in range(len(gas)):
      net += gas[i] - cost[i]
      summ += gas …

Category: leetcode

Read More
Page 11 of 146

« Prev Next »