67-Add-Binary

Fri 14 November 2025

https://leetcode.com/problems/add-binary

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def addBinary(self, a: str, b: str) -> str:
    s = []
    carry = 0
    i = len(a) - 1
    j = len(b) - 1

    while i >= 0 or j >= 0 or carry:
      if i …

Category: leetcode

Read More

670-Maximum-Swap

Fri 14 November 2025

https://leetcode.com/problems/maximum-swap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maximumSwap(self, num: int) -> int:
    s = list(str(num))
    dict = {c: i for i, c in enumerate(s)}

    for i, c in enumerate(s):
      for digit in reversed …

Category: leetcode

Read More

672-Bulb-Switcher-Ii

Fri 14 November 2025

https://leetcode.com/problems/bulb-switcher-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def flipLights(self, n: int, m: int) -> int:
    n = min(n, 3)

    if m == 0:
      return 1
    if m == 1:
      return [2, 3, 4][n - 1]
    if m == 2 …

Category: leetcode

Read More

673-Number-Of-Longest-Increasing-Subsequence

Fri 14 November 2025

https://leetcode.com/problems/number-of-longest-increasing-subsequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findNumberOfLIS(self, nums: List[int]) -> int:
    ans = 0
    maxLength = 0
    length = [1] * len(nums)  # length[i] := LIS's length ending w/ nums[i]
    count = [1] * len(nums)  # count …

Category: leetcode

Read More

674-Longest-Continuous-Increasing-Subsequence

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

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

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

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

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

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

« Prev Next »