283-Move-Zeroes

Fri 14 November 2025

https://leetcode.com/problems/move-zeroes

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def moveZeroes(self, nums: List[int]) -> None:
    j = 0
    for num in nums:
      if num != 0:
        nums[j] = num
        j += 1

    for i in range(j, len(nums)):
      nums …

Category: leetcode

Read More

285-Inorder-Successor-In-Bst

Fri 14 November 2025

https://leetcode.com/problems/inorder-successor-in-bst

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

Category: leetcode

Read More

286-Walls-And-Gates

Fri 14 November 2025

https://leetcode.com/problems/walls-and-gates

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def wallsAndGates(self, rooms: List[List[int]]) -> None:
    kInf = 2**31 - 1
    m = len(rooms)
    n = len(rooms[0])
    dirs = [0, 1, 0, -1, 0]
    q = deque()

    for i …

Category: leetcode

Read More

287-Find-The-Duplicate-Number

Fri 14 November 2025

https://leetcode.com/problems/find-the-duplicate-number

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

    while slow != fast:
      slow = nums[slow]
      fast = nums[nums[fast]]

    slow = nums[0 …

Category: leetcode

Read More

289-Game-Of-Life

Fri 14 November 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-Chaikin-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

29-Divide-Two-Integers

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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

Fri 14 November 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
Page 27 of 146

« Prev Next »