Added leetcode 383 and 733

This commit is contained in:
strNophix 2022-08-31 17:50:53 +02:00
parent 64cb9ea7ae
commit 38bf6a3084
2 changed files with 61 additions and 0 deletions

View 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

View 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