884-Uncommon-Words-From-Two-Sentences

Sat 17 May 2025

https://leetcode.com/problems/uncommon-words-from-two-sentences

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def uncommonFromSentences(self, A: str, B: str) -> List[str]:
    count = Counter((A + ' ' + B).split())
    return [word for word, freq in count.items() if freq == 1]
new Solution().uncommonFromSentences()

Score …

Category: leetcode

Read More

885-Spiral-Matrix-Iii

Sat 17 May 2025

https://leetcode.com/problems/spiral-matrix-iii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def spiralMatrixIII(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:
    ans = [[r0, c0]]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    i = 0 …

Category: leetcode

Read More

886-Possible-Bipartition

Sat 17 May 2025

https://leetcode.com/problems/possible-bipartition

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
from enum import Enum


class Color(Enum):
  kWhite = 0
  kRed = 1
  kGreen = 2


class Solution:
  def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:
    graph = [[] for _ in range(n …

Category: leetcode

Read More

888-Fair-Candy-Swap

Sat 17 May 2025

https://leetcode.com/problems/fair-candy-swap

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def fairCandySwap(self, A: List[int], B: List[int]) -> List[int]:
    diff = (sum(A) - sum(B)) // 2
    B = set(B)

    for a in A:
      if a - diff in B …

Category: leetcode

Read More

889-Construct-Binary-Tree-From-Preorder-And-Postorder-Traversal

Sat 17 May 2025

https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def constructFromPrePost(self, pre: List[int], post: List[int]) -> Optional[TreeNode]:
    postToIndex = {num: i for i, num in enumerate(post)}

    def build(preStart: int, preEnd: int, postStart: int, postEnd …

Category: leetcode

Read More

89-Gray-Code

Sat 17 May 2025

https://leetcode.com/problems/gray-code

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

    for i in range(n):
      for j in reversed(range(len(ans))):
        ans.append(ans[j] | 1 << i)

    return ans …

Category: leetcode

Read More

890-Find-And-Replace-Pattern

Sat 17 May 2025

https://leetcode.com/problems/find-and-replace-pattern

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
    def isIsomorphic(w: str, p: str) -> bool:
      return [*map(w.index, w)] == [*map(p.index, p)]
    return [word for …

Category: leetcode

Read More

891-Sum-Of-Subsequence-Widths

Sat 17 May 2025

https://leetcode.com/problems/sum-of-subsequence-widths

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def sumSubseqWidths(self, nums: List[int]) -> int:
    kMod = 1_000_000_007
    n = len(nums)
    ans = 0
    exp = 1

    nums.sort()

    for i in range(n):
      ans += (nums[i] - nums[n …

Category: leetcode

Read More

892-Surface-Area-Of-3D-Shapes

Sat 17 May 2025

https://leetcode.com/problems/surface-area-of-3d-shapes

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

    for i in range(len(grid)):
      for j in range(len(grid)):
        if grid[i][j]:
          ans += grid[i …

Category: leetcode

Read More

893-Groups-Of-Special-Equivalent-Strings

Sat 17 May 2025

https://leetcode.com/problems/groups-of-special-equivalent-strings

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def numSpecialEquivGroups(self, A: List[str]) -> int:
    return len({''.join(sorted(s[::2])) + ''.join(sorted(s[1::2])) for s in A})
new Solution().numSpecialEquivGroups()

Score: 5

Category: leetcode

Read More
Page 68 of 77

« Prev Next »