573-Squirrel-Simulation

Fri 14 November 2025

https://leetcode.com/problems/squirrel-simulation

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minDistance(self, height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:
    def dist(a: List[int], b: List[int]) -> int:
      return abs …

Category: leetcode

Read More

575-Distribute-Candies

Fri 14 November 2025

https://leetcode.com/problems/distribute-candies

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def distributeCandies(self, candies: List[int]) -> int:
    return min(len(candies) // 2, len(set(candies)))
new Solution().distributeCandies()

Score: 5

Category: leetcode

Read More

58-Length-Of-Last-Word

Fri 14 November 2025

https://leetcode.com/problems/length-of-last-word

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def lengthOfLastWord(self, s: str) -> int:
    i = len(s) - 1

    while i >= 0 and s[i] == ' ':
      i -= 1
    lastIndex = i
    while i >= 0 and s[i] != ' ':
      i -= 1

    return …

Category: leetcode

Read More

581-Shortest-Unsorted-Continuous-Subarray

Fri 14 November 2025

https://leetcode.com/problems/shortest-unsorted-continuous-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findUnsortedSubarray(self, nums: List[int]) -> int:
    mini = math.inf
    maxi = -math.inf
    flag = False

    for i in range(1, len(nums)):
      if nums[i] < nums[i - 1]:
        flag …

Category: leetcode

Read More

582-Kill-Process

Fri 14 November 2025

https://leetcode.com/problems/kill-process

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]:
    ans = []
    tree = defaultdict(list)

    for v, u in zip(pid, ppid):
      if u == 0:
        continue
      tree …

Category: leetcode

Read More

583-Delete-Operation-For-Two-Strings

Fri 14 November 2025

https://leetcode.com/problems/delete-operation-for-two-strings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minDistance(self, word1: str, word2: str) -> int:
    m = len(word1)
    n = len(word2)
    dp = [0] * (n + 1)

    for j in range(n + 1):
      dp[j] = j

    for i …

Category: leetcode

Read More

587-Erect-The-Fence

Fri 14 November 2025

https://leetcode.com/problems/erect-the-fence

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

    trees.sort(key=lambda x: (x[0], x[1]))

    def cross(p: List[int], q: List[int], r …

Category: leetcode

Read More

59-Spiral-Matrix-Ii

Fri 14 November 2025

https://leetcode.com/problems/spiral-matrix-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def generateMatrix(self, n: int) -> List[List[int]]:
    ans = [[0] * n for _ in range(n)]
    count = 1

    for min in range(n // 2):
      max = n - min - 1
      for …

Category: leetcode

Read More

591-Tag-Validator

Fri 14 November 2025

https://leetcode.com/problems/tag-validator

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isValid(self, code: str) -> bool:
    if code[0] != '<' or code[-1] != '>':
      return False

    containsTag = False
    stack = []

    def isValidCdata(s: str) -> bool:
      return s.find('[CDATA[') == 0

    def isValidTagName …

Category: leetcode

Read More

592-Fraction-Addition-And-Subtraction

Fri 14 November 2025

https://leetcode.com/problems/fraction-addition-and-subtraction

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def fractionAddition(self, expression: str) -> str:
    ints = list(map(int, re.findall('[+-]?[0-9]+', expression)))
    A = 0
    B = 1

    for a, b in zip(ints[::2], ints[1::2]):
      A …

Category: leetcode

Read More
Page 51 of 146

« Prev Next »