265-Paint-House-Ii

Fri 14 November 2025

https://leetcode.com/problems/paint-house-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minCostII(self, costs: List[List[int]]) -> int:
    prevIndex = -1  # The previous minimum index
    prevMin1 = 0    # Minimum cost so far
    prevMin2 = 0    # 2nd minimum cost so far

    for …

Category: leetcode

Read More

266-Palindrome-Permutation

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canPermutePalindrome(self, s: str) -> bool:
    seen = set()

    for c in s:
      if c in seen:
        seen.remove(c)
      else:
        seen.add(c)

    return len(seen) <= 1
new Solution …

Category: leetcode

Read More

267-Palindrome-Permutation-Ii

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def generatePalindromes(self, s: str) -> List[str]:
    # Get character occurrence
    count = Counter(s)

    # Count odd one
    odd = sum(value & 1 for value in count.values())

    # can't form any …

Category: leetcode

Read More

268-Missing-Number

Fri 14 November 2025

https://leetcode.com/problems/missing-number

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

    for i, num in enumerate(nums):
      ans ^= i ^ num

    return ans
new Solution().missingNumber()

Score: 5

Category: leetcode

Read More

269-Alien-Dictionary

Fri 14 November 2025

https://leetcode.com/problems/alien-dictionary

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def alienOrder(self, words: List[str]) -> str:
    graph = {}
    inDegree = [0] * 26

    self._buildGraph(graph, words, inDegree)
    return self._topology(graph, inDegree)

  def _buildGraph(self, graph: Dict[chr, Set[chr …

Category: leetcode

Read More

27-Remove-Element

Fri 14 November 2025

https://leetcode.com/problems/remove-element

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

    for num in nums:
      if num != val:
        nums[i] = num
        i += 1

    return i
new Solution().removeElement()

Score …

Category: leetcode

Read More

27-Stochastic-Oscillator

Fri 14 November 2025
# Created: 20250104
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("yfinance pandas matplotlib"))
yfinance==0.2.51
pandas==2.2.3
matplotlib==3.9.3
import …

Category: stockmarket

Read More

270-Closest-Binary-Search-Tree-Value

Fri 14 November 2025

https://leetcode.com/problems/closest-binary-search-tree-value

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def closestValue(self, root: Optional[TreeNode], target: float) -> int:
    # If target < root.val, search left subtree
    if target < root.val and root.left:
      left = self.closestValue(root.left, target …

Category: leetcode

Read More

272-Closest-Binary-Search-Tree-Value-Ii

Fri 14 November 2025

https://leetcode.com/problems/closest-binary-search-tree-value-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def closestKValues(self, root: Optional[TreeNode], target: float, k: int) -> List[int]:
    q = deque()

    def inorder(root: Optional[TreeNode]) -> None:
      if not root:
        return

      inorder(root.left)
      q.append …

Category: leetcode

Read More

273-Integer-To-English-Words

Fri 14 November 2025

https://leetcode.com/problems/integer-to-english-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numberToWords(self, num: int) -> str:
    if num == 0:
      return "Zero"

    belowTwenty = ["",        "One",       "Two",      "Three",
                   "Four",    "Five",      "Six",      "Seven",
                   "Eight",   "Nine",      "Ten",      "Eleven",
                   "Twelve",  "Thirteen",  "Fourteen", "Fifteen",
                   "Sixteen", "Seventeen …

Category: leetcode

Read More
Page 25 of 146

« Prev Next »