713-Subarray-Product-Less-Than-K

Sat 17 May 2025

https://leetcode.com/problems/subarray-product-less-than-k

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
    if k <= 1:
      return 0

    ans = 0
    prod = 1

    j = 0
    for i, num in enumerate(nums):
      prod *= num
      while …

Category: leetcode

Read More

714-Best-Time-To-Buy-And-Sell-Stock-With-Transaction-Fee

Sat 17 May 2025

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxProfit(self, prices: List[int], fee: int) -> int:
    sell = 0
    hold = -math.inf

    for price in prices:
      sell = max(sell, hold + price)
      hold = max(hold, sell - price - fee …

Category: leetcode

Read More

717-1-Bit-And-2-Bit-Characters

Sat 17 May 2025

https://leetcode.com/problems/1-bit-and-2-bit-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isOneBitCharacter(self, bits: List[int]) -> bool:
    i = 0
    while i < len(bits) - 1:
      i += bits[i] + 1

    return i == len(bits) - 1
new Solution().isOneBitCharacter()

Score: 5

Category: leetcode

Read More

718-Maximum-Length-Of-Repeated-Subarray

Sat 17 May 2025

https://leetcode.com/problems/maximum-length-of-repeated-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findLength(self, nums1: List[int], nums2: List[int]) -> int:
    m = len(nums1)
    n = len(nums2)
    ans = 0
    # dp[i][j] := max length of nums1[i:] and nums2[j …

Category: leetcode

Read More

719-Find-K-Th-Smallest-Pair-Distance

Sat 17 May 2025

https://leetcode.com/problems/find-k-th-smallest-pair-distance

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

    l = 0
    r = nums[-1] - nums[0]

    while l < r:
      m = (l + r) // 2
      count = 0

      j = 0 …

Category: leetcode

Read More

72-Edit-Distance

Sat 17 May 2025

https://leetcode.com/problems/edit-distance

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[i][j] := min # Of operations to convert word1[0..i) to word2[0..j …

Category: leetcode

Read More

720-Longest-Word-In-Dictionary

Sat 17 May 2025

https://leetcode.com/problems/longest-word-in-dictionary

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def longestWord(self, words: List[str]) -> str:
    root = {}

    for word in words:
      node = root
      for c in word:
        if c not in node:
          node[c] = {}
        node = node[c]
      node …

Category: leetcode

Read More

722-Remove-Comments

Sat 17 May 2025

https://leetcode.com/problems/remove-comments

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def removeComments(self, source: List[str]) -> List[str]:
    ans = []
    commenting = False
    modified = ''

    for line in source:
      i = 0
      while i < len(line):
        if i + 1 == len(line):
          if not …

Category: leetcode

Read More

724-Find-Pivot-Index

Sat 17 May 2025

https://leetcode.com/problems/find-pivot-index

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

    for i, num in enumerate(nums):
      if prefix == summ - prefix - num:
        return i
      prefix += num

    return -1 …

Category: leetcode

Read More

725-Split-Linked-List-In-Parts

Sat 17 May 2025

https://leetcode.com/problems/split-linked-list-in-parts

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def splitListToParts(self, root: ListNode, k: int) -> List[ListNode]:
    ans = [[] for _ in range(k)]
    length = 0
    curr = root
    while curr:
      length += 1
      curr = curr.next
    subLength = length // k …

Category: leetcode

Read More
Page 54 of 77

« Prev Next »