1078-Occurrences-After-Bigram

Sat 17 May 2025

https://leetcode.com/problems/occurrences-after-bigram

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findOcurrences(self, text: str, first: str, second: str) -> List[str]:
    words = text.split()
    return [c for a, b, c in zip(words, words[1:], words[2:]) if a …

Category: leetcode

Read More

1079-Letter-Tile-Possibilities

Sat 17 May 2025

https://leetcode.com/problems/letter-tile-possibilities

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numTilePossibilities(self, tiles: str) -> int:
    count = Counter(tiles)

    def dfs(count: Dict[int, int]) -> int:
      possibleSequences = 0

      for k, v in count.items():
        if v == 0:
          continue
        # Put …

Category: leetcode

Read More

108-Convert-Sorted-Array-To-Binary-Search-Tree

Sat 17 May 2025

https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]:
    def build(l: int, r: int) -> Optional[TreeNode]:
      if l > r:
        return None

      m = (l + r) // 2
      return TreeNode(nums[m …

Category: leetcode

Read More

1081-Smallest-Subsequence-Of-Distinct-Characters

Sat 17 May 2025

https://leetcode.com/problems/smallest-subsequence-of-distinct-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def smallestSubsequence(self, text: str) -> str:
    ans = []
    count = Counter(text)
    used = [False] * 26

    for c in text:
      count[c] -= 1
      if used[ord(c) - ord('a')]:
        continue
      while ans …

Category: leetcode

Read More

1087-Brace-Expansion

Sat 17 May 2025

https://leetcode.com/problems/brace-expansion

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

    def dfs(i: int, path: List[str]) -> None:
      if i == len(s):
        ans.append(''.join(path))
        return
      if s[i] == '{':
        nextRightBraceIndex …

Category: leetcode

Read More

1088-Confusing-Number-Ii

Sat 17 May 2025

https://leetcode.com/problems/confusing-number-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def confusingNumberII(self, n: int) -> int:
    digitToRotated = [(0, 0), (1, 1), (6, 9), (8, 8), (9, 6)]

    def dfs(num: int, rotatedNum: int, unit: int) -> int:
      ans = 0 if …

Category: leetcode

Read More

1089-Duplicate-Zeros

Sat 17 May 2025

https://leetcode.com/problems/duplicate-zeros

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def duplicateZeros(self, arr: List[int]) -> None:
    zeros = arr.count(0)
    i = len(arr) - 1
    j = len(arr) + zeros - 1

    while i < j:
      if j < len(arr):
        arr[j …

Category: leetcode

Read More

109-Convert-Sorted-List-To-Binary-Search-Tree

Sat 17 May 2025

https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sortedListToBST(self, head: ListNode) -> TreeNode:
    def findMid(head: ListNode) -> ListNode:
      prev = None
      slow = head
      fast = head

      while fast and fast.next:
        prev = slow
        slow = slow.next
        fast = fast …

Category: leetcode

Read More

11-Container-With-Most-Water

Sat 17 May 2025

https://leetcode.com/problems/container-with-most-water

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

    while l < r:
      minHeight = min(height[l], height[r])
      ans = max(ans, minHeight * (r …

Category: leetcode

Read More

11-Datashader-1

Sat 17 May 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 install datashader
!pip show datashader | grep "Version:"
Version: 0.16.3
import datashader as ds
import pandas as pd

df …

Category: plot-compare

Read More
Page 8 of 146

« Prev Next »