1015-Smallest-Integer-Divisible-By-K

Sat 17 May 2025

https://leetcode.com/problems/smallest-integer-divisible-by-k

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def smallestRepunitDivByK(self, K: int) -> int:
    if K % 10 not in {1, 3, 7, 9}:
      return -1

    seen = set()
    N = 0

    for length in range(1, K + 1):
      N …

Category: leetcode

Read More

1016-Binary-String-With-Substrings-Representing-1-To-N

Sat 17 May 2025

https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def queryString(self, S: str, N: int) -> bool:
    if N > 1511:
      return False

    for i in range(N, N // 2, -1):
      if format(i, 'b') not in S:
        return …

Category: leetcode

Read More

1017-Convert-To-Base-2

Sat 17 May 2025

https://leetcode.com/problems/convert-to-base-2

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def baseNeg2(self, N: int) -> str:
    ans = ''

    while N:
      ans = str(N & 1) + ans
      N = -(N >> 1)

    return '0' if ans == '' else ans
new Solution().baseNeg2()

Score: 5

Category: leetcode

Read More

1018-Binary-Prefix-Divisible-By-5

Sat 17 May 2025

https://leetcode.com/problems/binary-prefix-divisible-by-5

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

    for a in A:
      num = (num * 2 + a) % 5
      ans.append(num % 5 == 0)

    return ans
new Solution …

Category: leetcode

Read More

1019-Next-Greater-Node-In-Linked-List

Sat 17 May 2025

https://leetcode.com/problems/next-greater-node-in-linked-list

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def nextLargerNodes(self, head: ListNode) -> List[int]:
    ans = []
    stack = []

    while head:
      while stack and head.val > ans[stack[-1]]:
        index = stack.pop()
        ans[index] = head.val
      stack.append(len …

Category: leetcode

Read More

102-Binary-Tree-Level-Order-Traversal

Sat 17 May 2025

https://leetcode.com/problems/binary-tree-level-order-traversal

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

    ans = []
    q = deque([root])

    while q:
      currLevel = []
      for _ in range(len(q)):
        node = q.popleft …

Category: leetcode

Read More

1023-Camelcase-Matching

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
    def isMatch(q: str) -> bool:
      j = 0

      for i, c in enumerate(q):
        if j < len(pattern) and c …

Category: leetcode

Read More

1024-Video-Stitching

Sat 17 May 2025

https://leetcode.com/problems/video-stitching

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def videoStitching(self, clips: List[List[int]], time: int) -> int:
    ans = 0
    end = 0
    farthest = 0

    clips.sort()

    i = 0
    while farthest < time:
      while i < len(clips) and clips …

Category: leetcode

Read More

1025-Divisor-Game

Sat 17 May 2025

https://leetcode.com/problems/divisor-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def divisorGame(self, N: int) -> bool:
    return N % 2 == 0
new Solution().divisorGame()

Score: 5

Category: leetcode

Read More

1027-Longest-Arithmetic-Subsequence

Sat 17 May 2025

https://leetcode.com/problems/longest-arithmetic-subsequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def longestArithSeqLength(self, nums: List[int]) -> int:
    n = len(nums)
    ans = 0
    # dp[i][k] := length of the longest arithmetic subseq ofnums
    # nums[0..i] with k = diff + 500 …

Category: leetcode

Read More
Page 4 of 146

« Prev Next »