824-Goat-Latin

Fri 14 November 2025

https://leetcode.com/problems/goat-latin

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def toGoatLatin(self, S: str) -> str:
    ans = ''
    vowels = 'aeiouAEIOU'
    words = S.split()
    i = 1

    for word in words:
      if i > 1:
        ans += ' '
      if word[0] in vowels:
        ans += word …

Category: leetcode

Read More

825-Friends-Of-Appropriate-Ages

Fri 14 November 2025

https://leetcode.com/problems/friends-of-appropriate-ages

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numFriendRequests(self, ages: List[int]) -> int:
    ans = 0
    count = [0] * 121

    for age in ages:
      count[age] += 1

    for i in range(15, 121):
      ans += count[i] * (count …

Category: leetcode

Read More

826-Most-Profit-Assigning-Work

Fri 14 November 2025

https://leetcode.com/problems/most-profit-assigning-work

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
    ans = 0
    jobs = sorted(zip(difficulty, profit))
    worker.sort(reverse=1)

    i = 0
    maxProfit = 0

    for …

Category: leetcode

Read More

828-Count-Unique-Characters-Of-All-Substrings-Of-A-Given-String

Fri 14 November 2025

https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def uniqueLetterString(self, s: str) -> int:
    ans = 0
    count = 0
    lastCount = [0] * 26
    lastSeen = [-1] * 26

    for i, c in enumerate(s):
      c = ord(c) - ord('A')
      currentCount = i …

Category: leetcode

Read More

829-Consecutive-Numbers-Sum

Fri 14 November 2025

https://leetcode.com/problems/consecutive-numbers-sum

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def consecutiveNumbersSum(self, N: int) -> int:
    ans = 0
    i = 1
    triangleNum = 1

    while triangleNum <= N:
      if (N - triangleNum) % i == 0:
        ans += 1
      i += 1
      triangleNum += i

    return ans
new …

Category: leetcode

Read More

83-Remove-Duplicates-From-Sorted-List

Fri 14 November 2025

https://leetcode.com/problems/remove-duplicates-from-sorted-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def deleteDuplicates(self, head: ListNode) -> ListNode:
    curr = head

    while curr:
      while curr.next and curr.val == curr.next.val:
        curr.next = curr.next.next
      curr = curr.next

    return head …

Category: leetcode

Read More

830-Positions-Of-Large-Groups

Fri 14 November 2025

https://leetcode.com/problems/positions-of-large-groups

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def largeGroupPositions(self, S: str) -> List[List[int]]:
    n = len(S)
    ans = []
    i = 0
    j = 0

    while i < n:
      while j < n and S[j] == S[i]:
        j += 1 …

Category: leetcode

Read More

831-Masking-Personal-Information

Fri 14 November 2025

https://leetcode.com/problems/masking-personal-information

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maskPII(self, S: str) -> str:
    atIndex = S.find('@')
    if atIndex != -1:
      S = S.lower()
      return S[0] + '*' * 5 + S[atIndex - 1:]

    ans = ''.join(c for c in S …

Category: leetcode

Read More

832-Flipping-An-Image

Fri 14 November 2025

https://leetcode.com/problems/flipping-an-image

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

    for i in range(n):
      for j in range((n + 2) // 2):
        A[i][j], A …

Category: leetcode

Read More

833-Find-And-Replace-In-String

Fri 14 November 2025

https://leetcode.com/problems/find-and-replace-in-string

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findReplaceString(self, s: str, indexes: List[int],
                        sources: List[str], targets: List[str]) -> str:
    for index, source, target in sorted(zip(indexes, sources, targets), reverse=True):
      if s …

Category: leetcode

Read More
Page 69 of 146

« Prev Next »