Added leetcode 383 and 733
This commit is contained in:
parent
64cb9ea7ae
commit
38bf6a3084
17
leetcode/383_ransom_note.py
Normal file
17
leetcode/383_ransom_note.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import pytest
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
|
||||||
|
return not Counter(ransomNote) - Counter(magazine)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def solution():
|
||||||
|
return Solution()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("", [])
|
||||||
|
def test_search(solution: Solution):
|
||||||
|
pass
|
44
leetcode/733_flood_fill.py
Normal file
44
leetcode/733_flood_fill.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def floodFill(
|
||||||
|
self, image: list[list[int]], sr: int, sc: int, color: int
|
||||||
|
) -> list[list[int]]:
|
||||||
|
orig = image[sr][sc]
|
||||||
|
|
||||||
|
def dfs(i: int, j: int):
|
||||||
|
if (
|
||||||
|
0 <= i < len(image)
|
||||||
|
and 0 <= j < len(image[0])
|
||||||
|
and image[i][j] == orig
|
||||||
|
and image[i][j] != color
|
||||||
|
):
|
||||||
|
image[i][j] = color
|
||||||
|
dfs(i + 1, j)
|
||||||
|
dfs(i - 1, j)
|
||||||
|
dfs(i, j + 1)
|
||||||
|
dfs(i, j - 1)
|
||||||
|
|
||||||
|
dfs(sr, sc)
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def solution():
|
||||||
|
return Solution()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"image, sr, sc, color, expected",
|
||||||
|
[([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]])],
|
||||||
|
)
|
||||||
|
def test_search(
|
||||||
|
solution: Solution,
|
||||||
|
image: list[list[int]],
|
||||||
|
sr: int,
|
||||||
|
sc: int,
|
||||||
|
color: int,
|
||||||
|
expected: list[list[int]],
|
||||||
|
):
|
||||||
|
assert solution.floodFill(image, sr, sc, color) == expected
|
Loading…
x
Reference in New Issue
Block a user