674-Longest-Continuous-Increasing-Subsequence

Sat 17 May 2025

https://leetcode.com/problems/longest-continuous-increasing-subsequence

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

    for i in range(len(nums)):
      if i > 0 and nums[i] <= nums[i - 1]:
        j = i
      ans …

Category: leetcode

Read More

678-Valid-Parenthesis-String

Sat 17 May 2025

https://leetcode.com/problems/valid-parenthesis-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def checkValidString(self, s: str) -> bool:
    low = 0
    high = 0

    for c in s:
      if c == '(':
        low += 1
        high += 1
      elif c == ')':
        if low > 0:
          low -= 1
        high -= 1 …

Category: leetcode

Read More

679-24-Game

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def judgePoint24(self, nums: List[int]) -> bool:
    def generate(a: float, b: float) -> List[float]:
      return [a * b,
              math.inf if b == 0 else a / b,
              math.inf if …

Category: leetcode

Read More

68-Text-Justification

Sat 17 May 2025

https://leetcode.com/problems/text-justification

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

    for word in words:
      if rowLetters + len(word) + len(row) > maxWidth:
        for i in range …

Category: leetcode

Read More

680-Valid-Palindrome-Ii

Sat 17 May 2025

https://leetcode.com/problems/valid-palindrome-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def validPalindrome(self, s: str) -> bool:
    def validPalindrome(l: int, r: int) -> bool:
      return all(s[i] == s[r - i + l] for i in range(l, (l + r) // 2 …

Category: leetcode

Read More

681-Next-Closest-Time

Sat 17 May 2025

https://leetcode.com/problems/next-closest-time

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nextClosestTime(self, time: str) -> str:
    ans = list(time)
    digits = sorted(ans)

    def nextClosest(digit: chr, limit: chr) -> chr:
      next = bisect_right(digits, digit)
      return digits[0] if next == 4 …

Category: leetcode

Read More

683-K-Empty-Slots

Sat 17 May 2025

https://leetcode.com/problems/k-empty-slots

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def kEmptySlots(self, bulbs: List[int], k: int) -> int:
    n = len(bulbs)
    ans = math.inf
    # day[i] := the day when bulbs[i] is turned on
    day = [0] * n

    for …

Category: leetcode

Read More

684-Redundant-Connection

Sat 17 May 2025

https://leetcode.com/problems/redundant-connection

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class UnionFind:
  def __init__(self, n: int):
    self.id = [i for i in range(n + 1)]

  def union(self, u: int, v: int) -> bool:
    i = self.find(u)
    j = self.find …

Category: leetcode

Read More

685-Redundant-Connection-Ii

Sat 17 May 2025

https://leetcode.com/problems/redundant-connection-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class UnionFind:
  def __init__(self, n: int):
    self.id = [i for i in range(n + 1)]

  def union(self, u: int, v: int) -> bool:
    i = self.find(u)
    j = self.find …

Category: leetcode

Read More

686-Repeated-String-Match

Sat 17 May 2025

https://leetcode.com/problems/repeated-string-match

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def repeatedStringMatch(self, a: str, b: str) -> int:
    n = ceil(len(b) / len(a))
    s = a * n
    if b in s:
      return n
    if b in s + a:
      return …

Category: leetcode

Read More
Page 51 of 77

« Prev Next »