692-Top-K-Frequent-Words

Fri 14 November 2025

https://leetcode.com/problems/top-k-frequent-words

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def topKFrequent(self, words: List[str], k: int) -> List[str]:
    ans = []
    bucket = [[] for _ in range(len(words) + 1)]

    for word, freq in Counter(words).items():
      bucket[freq].append …

Category: leetcode

Read More

694-Number-Of-Distinct-Islands

Fri 14 November 2025

https://leetcode.com/problems/number-of-distinct-islands

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

    def dfs(i: int, j: int, i0: int, j0: int):
      if i < 0 or i == len(grid) or j …

Category: leetcode

Read More

695-Max-Area-Of-Island

Fri 14 November 2025

https://leetcode.com/problems/max-area-of-island

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
    def dfs(i: int, j: int) -> int:
      if i < 0 or i == len(grid) or j < 0 or j == len(grid …

Category: leetcode

Read More

696-Count-Binary-Substrings

Fri 14 November 2025

https://leetcode.com/problems/count-binary-substrings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def countBinarySubstrings(self, s: str) -> int:
    ans = 0
    prevCount = 0
    equals = 1

    for i in range(len(s) - 1):
      if s[i] == s[i + 1]:
        equals += 1
      else:
        ans …

Category: leetcode

Read More

697-Degree-Of-An-Array

Fri 14 November 2025

https://leetcode.com/problems/degree-of-an-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findShortestSubArray(self, nums: List[int]) -> int:
    ans = 0
    degree = 0
    debut = {}
    count = Counter()

    for i, num in enumerate(nums):
      debut.setdefault(num, i)
      count[num] += 1
      if count …

Category: leetcode

Read More

7-Dash-1

Fri 14 November 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'

!pip show dash | grep "Version:"
Version: 2.18.2
from dash import Dash, dcc, html
import plotly.express as px

app …

Category: plot-compare

Read More

7-Reverse-Integer

Fri 14 November 2025

https://leetcode.com/problems/reverse-integer

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverse(self, x: int) -> int:
    ans = 0
    sign = -1 if x < 0 else 1
    x *= sign

    while x:
      ans = ans * 10 + x % 10
      x //= 10

    return 0 if …

Category: leetcode

Read More

70-Climbing-Stairs

Fri 14 November 2025

https://leetcode.com/problems/climbing-stairs

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def climbStairs(self, n: int) -> int:
    # dp[i] := # Of distinct ways to climb to i-th stair
    dp = [1, 1] + [0] * (n - 1)

    for i in range(2, n …

Category: leetcode

Read More

700-Search-In-A-Binary-Search-Tree

Fri 14 November 2025

https://leetcode.com/problems/search-in-a-binary-search-tree

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

Category: leetcode

Read More

701-Insert-Into-A-Binary-Search-Tree

Fri 14 November 2025

https://leetcode.com/problems/insert-into-a-binary-search-tree

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

Category: leetcode

Read More
Page 59 of 146

« Prev Next »