948-Bag-Of-Tokens

Fri 14 November 2025

https://leetcode.com/problems/bag-of-tokens

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def bagOfTokensScore(self, tokens: List[int], power: int) -> int:
    ans = 0
    score = 0
    q = deque(sorted(tokens))

    while q and (power >= q[0] or score):
      while q and power …

Category: leetcode

Read More

949-Largest-Time-For-Given-Digits

Fri 14 November 2025

https://leetcode.com/problems/largest-time-for-given-digits

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def largestTimeFromDigits(self, A: List[int]) -> str:
    for time in itertools.permutations(sorted(A, reverse=True)):
      if time[:2] < (2, 4) and time[2] < 6:
        return '%d%d:%d …

Category: leetcode

Read More

95-Unique-Binary-Search-Trees-Ii

Fri 14 November 2025

https://leetcode.com/problems/unique-binary-search-trees-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def generateTrees(self, n: int) -> List[TreeNode]:
    if n == 0:
      return []

    def generateTrees(mini: int, maxi: int) -> List[Optional[int]]:
      if mini > maxi:
        return [None]

      ans = []

      for i in …

Category: leetcode

Read More

950-Reveal-Cards-In-Increasing-Order

Fri 14 November 2025

https://leetcode.com/problems/reveal-cards-in-increasing-order

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:
    q = deque()

    for card in reversed(sorted(deck)):
      q.rotate()
      q.appendleft(card)

    return list(q)
new Solution().deckRevealedIncreasing()

Score: 5 …

Category: leetcode

Read More

951-Flip-Equivalent-Binary-Trees

Fri 14 November 2025

https://leetcode.com/problems/flip-equivalent-binary-trees

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def flipEquiv(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:
    if not root1:
      return not root2
    if not root2:
      return not root1
    if root1.val != root2.val:
      return False …

Category: leetcode

Read More

952-Largest-Component-Size-By-Common-Factor

Fri 14 November 2025

https://leetcode.com/problems/largest-component-size-by-common-factor

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class UnionFind:
  def __init__(self, n: int):
    self.id = [i for i in range(n + 1)]

  def union(self, u: int, v: int) -> bool:
    i = self.find(u)
    j = self.find …

Category: leetcode

Read More

953-Verifying-An-Alien-Dictionary

Fri 14 November 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isAlienSorted(self, words: List[str], order: str) -> bool:
    dict = {c: i for i, c in enumerate(order)}
    words = [[dict[c] for c in word] for word in words …

Category: leetcode

Read More

954-Array-Of-Doubled-Pairs

Fri 14 November 2025

https://leetcode.com/problems/array-of-doubled-pairs

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canReorderDoubled(self, A: List[int]) -> bool:
    count = Counter(A)

    for key in sorted(count, key=abs):
      if count[key] > count[2 * key]:
        return False
      count[2 * key] -= count …

Category: leetcode

Read More

957-Prison-Cells-After-N-Days

Fri 14 November 2025

https://leetcode.com/problems/prison-cells-after-n-days

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
    nextDayCells = [0] * len(cells)
    day = 0

    while N > 0:
      N -= 1
      for i in range(1, len(cells) - 1 …

Category: leetcode

Read More

96-Unique-Binary-Search-Trees

Fri 14 November 2025

https://leetcode.com/problems/unique-binary-search-trees

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numTrees(self, n: int) -> int:
    # G[i] := # Of unique BST's that store values 1..i
    G = [1, 1] + [0] * (n - 1)

    for i in range(2, n …

Category: leetcode

Read More
Page 80 of 146

« Prev Next »