770-Basic-Calculator-Iv

Sat 17 May 2025

https://leetcode.com/problems/basic-calculator-iv

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Poly:
  def __init__(self, term: str = None, coef: int = None):
    if term and coef:
      self.terms = Counter({term: coef})
    else:
      self.terms = Counter()

  def __add__(self, other):
    for …

Category: leetcode

Read More

771-Jewels-And-Stones

Sat 17 May 2025

https://leetcode.com/problems/jewels-and-stones

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numJewelsInStones(self, J: str, S: str) -> int:
    jewels = set(J)
    return sum(s in jewels for s in S)
new Solution().numJewelsInStones()

Score: 5

Category: leetcode

Read More

772-Basic-Calculator-Iii

Sat 17 May 2025

https://leetcode.com/problems/basic-calculator-iii

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

    def calc():
      b = nums.pop()
      a = nums.pop()
      op = ops.pop()
      if op == '+':
        nums.append(a + b)
      elif op == '-':
        nums.append …

Category: leetcode

Read More

774-Minimize-Max-Distance-To-Gas-Station

Sat 17 May 2025

https://leetcode.com/problems/minimize-max-distance-to-gas-station

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minmaxGasDist(self, stations: List[int], k: int) -> float:
    kErr = 1e-6
    l = 0
    r = stations[-1] - stations[0]

    # True if can use k or less gas stations to ensure …

Category: leetcode

Read More

775-Global-And-Local-Inversions

Sat 17 May 2025

https://leetcode.com/problems/global-and-local-inversions

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isIdealPermutation(self, A: List[int]) -> bool:
    for i, a in enumerate(A):
      if abs(a - i) > 1:
        return False

    return True
new Solution().isIdealPermutation()

Score: 5

Category: leetcode

Read More

776-Split-Bst

Sat 17 May 2025

https://leetcode.com/problems/split-bst

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

Category: leetcode

Read More

78-Subsets

Sat 17 May 2025

https://leetcode.com/problems/subsets

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

    def dfs(s: int, path: List[int]) -> None:
      ans.append(path)

      for i in range(s, len(nums)):
        dfs …

Category: leetcode

Read More

780-Reaching-Points

Sat 17 May 2025

https://leetcode.com/problems/reaching-points

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
    while sx < tx and sy < ty:
      tx, ty = tx % ty, ty % tx

    return sx == tx and sy …

Category: leetcode

Read More

781-Rabbits-In-Forest

Sat 17 May 2025

https://leetcode.com/problems/rabbits-in-forest

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

    for answer in answers:
      if count[answer] % (answer + 1) == 0:
        ans += answer + 1
      count[answer] += 1

    return ans …

Category: leetcode

Read More

782-Transform-To-Chessboard

Sat 17 May 2025

https://leetcode.com/problems/transform-to-chessboard

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

    if any(board[0][0] ^ board[i][0] ^ board[0][j] ^ board[i][j] for i in range …

Category: leetcode

Read More
Page 58 of 77

« Prev Next »