970-Powerful-Integers

Sat 17 May 2025

https://leetcode.com/problems/powerful-integers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
    xs = {x**i for i in range(20) if x**i < bound}
    ys = {y**i for i in …

Category: leetcode

Read More

972-Equal-Rational-Numbers

Sat 17 May 2025

https://leetcode.com/problems/equal-rational-numbers

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isRationalEqual(self, S: str, T: str) -> bool:
    def valueOf(s: str) -> float:
      if s.find('(') == -1:
        return float(s)

      integer_nonRepeating = float(s[:s.find('(')])
      nonRepeatingLength = s.find('(') - s …

Category: leetcode

Read More

973-K-Closest-Points-To-Origin

Sat 17 May 2025

https://leetcode.com/problems/k-closest-points-to-origin

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
    maxHeap = []

    for x, y in points:
      heapq.heappush(maxHeap, (- x * x - y * y, [x, y]))
      if len …

Category: leetcode

Read More

974-Subarray-Sums-Divisible-By-K

Sat 17 May 2025

https://leetcode.com/problems/subarray-sums-divisible-by-k

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def subarraysDivByK(self, A: List[int], K: int) -> int:
    ans = 0
    prefix = 0
    count = [1] + [0] * (K - 1)

    for a in A:
      prefix = (prefix + a) % K
      ans += count[prefix …

Category: leetcode

Read More

976-Largest-Perimeter-Triangle

Sat 17 May 2025

https://leetcode.com/problems/largest-perimeter-triangle

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

    for i in range(len(A) - 1, 1, -1):
      if A[i - 2] + A[i - 1] > A[i]:
        return …

Category: leetcode

Read More

977-Squares-Of-A-Sorted-Array

Sat 17 May 2025

https://leetcode.com/problems/squares-of-a-sorted-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortedSquares(self, A: List[int]) -> List[int]:
    n = len(A)
    l = 0
    r = n - 1
    ans = [0] * n

    while n:
      n -= 1
      if abs(A[l]) > abs(A …

Category: leetcode

Read More

978-Longest-Turbulent-Subarray

Sat 17 May 2025

https://leetcode.com/problems/longest-turbulent-subarray

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxTurbulenceSize(self, A: List[int]) -> int:
    ans = 1
    increasing = 1
    decreasing = 1

    for i in range(1, len(A)):
      if A[i] > A[i - 1]:
        increasing = decreasing + 1 …

Category: leetcode

Read More

98-Validate-Binary-Search-Tree

Sat 17 May 2025

https://leetcode.com/problems/validate-binary-search-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isValidBST(self, root: Optional[TreeNode]) -> bool:
    def isValidBST(root: Optional[TreeNode],
                   minNode: Optional[TreeNode], maxNode: Optional[TreeNode]) -> bool:
      if not root:
        return True
      if minNode and root.val …

Category: leetcode

Read More

983-Minimum-Cost-For-Tickets

Sat 17 May 2025

https://leetcode.com/problems/minimum-cost-for-tickets

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def mincostTickets(self, days: List[int], costs: List[int]) -> int:
    ans = 0
    last7 = deque()
    last30 = deque()

    for day in days:
      while last7 and last7[0][0] + 7 <= day:
        last7 …

Category: leetcode

Read More

985-Sum-Of-Even-Numbers-After-Queries

Sat 17 May 2025

https://leetcode.com/problems/sum-of-even-numbers-after-queries

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]:
    ans = []
    summ = sum(a for a in A if a % 2 == 0)

    for q in queries:
      if …

Category: leetcode

Read More
Page 75 of 77

« Prev Next »