424-Longest-Repeating-Character-Replacement

Sat 17 May 2025

https://leetcode.com/problems/longest-repeating-character-replacement

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def characterReplacement(self, s: str, k: int) -> int:
    ans = 0
    maxCount = 0
    count = Counter()

    l = 0
    for r, c in enumerate(s):
      count[c] += 1
      maxCount = max(maxCount, count …

Category: leetcode

Read More

43-Multiply-Strings

Sat 17 May 2025

https://leetcode.com/problems/multiply-strings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def multiply(self, num1: str, num2: str) -> str:
    s = [0] * (len(num1) + len(num2))

    for i in reversed(range(len(num1))):
      for j in reversed(range(len(num2))):
        mult …

Category: leetcode

Read More

430-Flatten-A-Multilevel-Doubly-Linked-List

Sat 17 May 2025

https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def flatten(self, head: 'Node') -> 'Node':
    def flatten(head: 'Node', rest: 'Node') -> 'Node':
      if not head:
        return rest

      head.next = flatten(head.child, flatten(head.next, rest))
      if head …

Category: leetcode

Read More

434-Number-Of-Segments-In-A-String

Sat 17 May 2025

https://leetcode.com/problems/number-of-segments-in-a-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countSegments(self, s: str) -> int:
    return len(s.split())
new Solution().countSegments()

Score: 5

Category: leetcode

Read More

435-Non-Overlapping-Intervals

Sat 17 May 2025

https://leetcode.com/problems/non-overlapping-intervals

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

    for interval in sorted(intervals, key=lambda x: x[1]):
      if interval[0] >= currentEnd:
        currentEnd = interval …

Category: leetcode

Read More

437-Path-Sum-Iii

Sat 17 May 2025

https://leetcode.com/problems/path-sum-iii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def pathSum(self, root: TreeNode, summ: int) -> int:
    if not root:
      return 0

    def dfs(root: TreeNode, summ: int) -> int:
      if not root:
        return 0
      return (summ == root.val …

Category: leetcode

Read More

438-Find-All-Anagrams-In-A-String

Sat 17 May 2025

https://leetcode.com/problems/find-all-anagrams-in-a-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findAnagrams(self, s: str, p: str) -> List[int]:
    ans = []
    count = Counter(p)
    required = len(p)

    for r, c in enumerate(s):
      count[c] -= 1
      if count[c] >= 0 …

Category: leetcode

Read More

439-Ternary-Expression-Parser

Sat 17 May 2025

https://leetcode.com/problems/ternary-expression-parser

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def parseTernary(self, expression: str) -> str:
    c = expression[self.i]

    if self.i + 1 == len(expression) or expression[self.i + 1] == ':':
      self.i += 2
      return str(c)

    self.i …

Category: leetcode

Read More

44-Wildcard-Matching

Sat 17 May 2025

https://leetcode.com/problems/wildcard-matching

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isMatch(self, s: str, p: str) -> bool:
    m = len(s)
    n = len(p)
    # dp[i][j] := True if s[0..i) matches p[0..j)
    dp = [[False] * (n …

Category: leetcode

Read More

441-Arranging-Coins

Sat 17 May 2025

https://leetcode.com/problems/arranging-coins

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def arrangeCoins(self, n: int) -> int:
    return int((-1 + sqrt(8 * n + 1)) // 2)
new Solution().arrangeCoins()

Score: 5

Category: leetcode

Read More
Page 34 of 77

« Prev Next »