917-Reverse-Only-Letters

Sat 17 May 2025

https://leetcode.com/problems/reverse-only-letters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseOnlyLetters(self, S: str) -> str:
    S = list(S)
    i = 0
    j = len(S) - 1

    while i < j:
      while i < j and not S[i].isalpha():
        i += 1
      while …

Category: leetcode

Read More

918-Maximum-Sum-Circular-Subarray

Sat 17 May 2025

https://leetcode.com/problems/maximum-sum-circular-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxSubarraySumCircular(self, A: List[int]) -> int:
    totalSum = 0
    currMaxSum = 0
    currMinSum = 0
    maxSum = -math.inf
    minSum = math.inf

    for a in A:
      totalSum += a
      currMaxSum = max(currMaxSum + a …

Category: leetcode

Read More

92-Reverse-Linked-List-Ii

Sat 17 May 2025

https://leetcode.com/problems/reverse-linked-list-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]:
    if left == 1:
      return self.reverseN(head, right)

    head.next = self.reverseBetween(head.next, left - 1, right …

Category: leetcode

Read More

921-Minimum-Add-To-Make-Parentheses-Valid

Sat 17 May 2025

https://leetcode.com/problems/minimum-add-to-make-parentheses-valid

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minAddToMakeValid(self, s: str) -> int:
    l = 0
    r = 0

    for c in s:
      if c == '(':
        l += 1
      else:
        if l == 0:
          r += 1
        else:
          l -= 1

    return l …

Category: leetcode

Read More

922-Sort-Array-By-Parity-Ii

Sat 17 May 2025

https://leetcode.com/problems/sort-array-by-parity-ii

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

    i = 0
    j = 1
    while i < n:
      while i < n and A[i] % 2 == 0:
        i += 2
      while …

Category: leetcode

Read More

925-Long-Pressed-Name

Sat 17 May 2025

https://leetcode.com/problems/long-pressed-name

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isLongPressedName(self, name: str, typed: str) -> bool:
    i = 0

    for j, t in enumerate(typed):
      if i < len(name) and name[i] == t:
        i += 1
      elif j == 0 …

Category: leetcode

Read More

926-Flip-String-To-Monotone-Increasing

Sat 17 May 2025

https://leetcode.com/problems/flip-string-to-monotone-increasing

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minFlipsMonoIncr(self, S: str) -> int:
    dp = [0] * 2

    for i, c in enumerate(S):
      dp[0], dp[1] = dp[0] + (c == '1'), min(dp[0], dp[1]) + (c …

Category: leetcode

Read More

927-Three-Equal-Parts

Sat 17 May 2025

https://leetcode.com/problems/three-equal-parts

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def threeEqualParts(self, A: List[int]) -> List[int]:
    ones = sum(a == 1 for a in A)

    if ones == 0:
      return [0, len(A) - 1]
    if ones % 3 != 0:
      return …

Category: leetcode

Read More

929-Unique-Email-Addresses

Sat 17 May 2025

https://leetcode.com/problems/unique-email-addresses

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numUniqueEmails(self, emails: List[str]) -> int:
    seen = set()

    for email in emails:
      local, domain = email.split('@')
      local = local.split('+')[0].replace('.', '')
      seen.add(local + '@' + domain)

    return len(seen …

Category: leetcode

Read More

93-Restore-Ip-Addresses

Sat 17 May 2025

https://leetcode.com/problems/restore-ip-addresses

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

    def dfs(start: int, path: List[int]) -> None:
      if len(path) == 4 and start == len(s):
        ans.append(path[0] + '.' + path …

Category: leetcode

Read More
Page 71 of 77

« Prev Next »