289-Game-Of-Life

Sat 17 May 2025

https://leetcode.com/problems/game-of-life

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def gameOfLife(self, board: List[List[int]]) -> None:
    m = len(board)
    n = len(board[0])

    for i in range(m):
      for j in range(n):
        ones = 0
        for x …

Category: leetcode

Read More

29-Divide-Two-Integers

Sat 17 May 2025

https://leetcode.com/problems/divide-two-integers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def divide(self, dividend: int, divisor: int) -> int:
    if dividend == -2**31 and divisor == -1:
      return 2**31 - 1

    sign = -1 if (dividend > 0) ^ (divisor > 0) else 1
    ans …

Category: leetcode

Read More

290-Word-Pattern

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def wordPattern(self, pattern: str, str: str) -> bool:
    t = str.split()
    return [*map(pattern.index, pattern)] == [*map(t.index, t)]
new Solution().wordPattern()

Score: 5

Category: leetcode

Read More

291-Word-Pattern-Ii

Sat 17 May 2025

https://leetcode.com/problems/word-pattern-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def wordPatternMatch(self, pattern: str, s: str) -> bool:
    def isMatch(i: int, j: int, charToString: Dict[chr, str], seen: Set[str]) -> bool:
      if i == len(pattern) and j == len …

Category: leetcode

Read More

292-Nim-Game

Sat 17 May 2025

https://leetcode.com/problems/nim-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def canWinNim(self, n: int) -> bool:
    return n % 4 != 0
new Solution().canWinNim()

Score: 5

Category: leetcode

Read More

293-Flip-Game

Sat 17 May 2025

https://leetcode.com/problems/flip-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def generatePossibleNextMoves(self, currentState: str) -> List[str]:
    return [currentState[:i] + '--' + currentState[i + 2:]
            for i, (a, b) in enumerate(zip(currentState, currentState[1:]))
            if a == '+' and b == '+']
new Solution …

Category: leetcode

Read More

294-Flip-Game-Ii

Sat 17 May 2025

https://leetcode.com/problems/flip-game-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  @functools.lru_cache(None)
  def canWin(self, currentState: str) -> bool:
    # If any of currentState[i:i + 2] == "++" and your friend can't win after
    # Changing currentState[i:i + 2] to …

Category: leetcode

Read More

296-Best-Meeting-Point

Sat 17 May 2025

https://leetcode.com/problems/best-meeting-point

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minTotalDistance(self, grid: List[List[int]]) -> int:
    m = len(grid)
    n = len(grid[0])
    # I indices s.t. grid[i][j] == 1
    I = [i for i in range …

Category: leetcode

Read More

298-Binary-Tree-Longest-Consecutive-Sequence

Sat 17 May 2025

https://leetcode.com/problems/binary-tree-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, root: Optional[TreeNode]) -> int:
    if not root:
      return 0

    def dfs(root: Optional[TreeNode], target: int, length: int, maxLength: int) -> int:
      if not root:
        return maxLength …

Category: leetcode

Read More

299-Bulls-And-Cows

Sat 17 May 2025

https://leetcode.com/problems/bulls-and-cows

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def getHint(self, secret: str, guess: str) -> str:
    bulls = sum(map(operator.eq, secret, guess))
    bovine = sum(min(secret.count(x), guess.count(x)) for x in set(guess …

Category: leetcode

Read More
Page 24 of 77

« Prev Next »