55-Jump-Game

Sat 17 May 2025

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

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

    while i < len(nums) and i <= reach:
      reach = max(reach, i + nums[i])
      i += 1

    return i == len …

Category: leetcode

Read More

551-Student-Attendance-Record-I

Sat 17 May 2025

https://leetcode.com/problems/student-attendance-record-i

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def checkRecord(self, s: str) -> bool:
    return s.count('A') <= 1 and 'LLL' not in s
new Solution().checkRecord()

Score: 5

Category: leetcode

Read More

552-Student-Attendance-Record-Ii

Sat 17 May 2025

https://leetcode.com/problems/student-attendance-record-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def checkRecord(self, n: int) -> int:
    kMod = 1_000_000_007
    # dp[i][j] := length so far w/ i A's and the latest chars are j L's
    dp = [[0 …

Category: leetcode

Read More

553-Optimal-Division

Sat 17 May 2025

https://leetcode.com/problems/optimal-division

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

    if len(nums) == 1:
      return ans
    if len(nums) == 2:
      return ans + '/' + str(nums[1])

    ans += '/(' + str(nums …

Category: leetcode

Read More

554-Brick-Wall

Sat 17 May 2025

https://leetcode.com/problems/brick-wall

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def leastBricks(self, wall: List[List[int]]) -> int:
    maxFreq = 0
    count = defaultdict(int)

    for row in wall:
      prefix = 0
      for i in range(len(row) - 1):
        prefix += row[i …

Category: leetcode

Read More

555-Split-Concatenated-Strings

Sat 17 May 2025

https://leetcode.com/problems/split-concatenated-strings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def splitLoopedString(self, strs: List[str]) -> str:
    ans = ''
    sortedStrs = [max(s, s[::-1]) for s in strs]

    for i, sortedStr in enumerate(sortedStrs):
      for s in (sortedStr, sortedStr[::-1 …

Category: leetcode

Read More

556-Next-Greater-Element-Iii

Sat 17 May 2025

https://leetcode.com/problems/next-greater-element-iii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nextGreaterElement(self, n: int) -> int:
    def nextPermutation(s: List[chr]) -> str:
      i = len(s) - 2
      while i >= 0:
        if s[i] < s[i + 1]:
          break
        i -= 1

      if …

Category: leetcode

Read More

559-Maximum-Depth-Of-N-Ary-Tree

Sat 17 May 2025

https://leetcode.com/problems/maximum-depth-of-n-ary-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxDepth(self, root: 'Node') -> int:
    if not root:
      return 0
    if not root.children:
      return 1
    return 1 + max(self.maxDepth(child) for child in root.children)
new …

Category: leetcode

Read More

56-Merge-Intervals

Sat 17 May 2025

https://leetcode.com/problems/merge-intervals

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

    for interval in sorted(intervals):
      if not ans or ans[-1][1] < interval[0]:
        ans.append(interval)
      else …

Category: leetcode

Read More

560-Subarray-Sum-Equals-K

Sat 17 May 2025

https://leetcode.com/problems/subarray-sum-equals-k

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def subarraySum(self, nums: List[int], k: int) -> int:
    ans = 0
    prefix = 0
    count = Counter({0: 1})

    for num in nums:
      prefix += num
      ans += count[prefix - k]
      count[prefix …

Category: leetcode

Read More
Page 43 of 77

« Prev Next »