Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 28cc996

Browse files
authored
feat: [LeetCode #2215] Find The Difference Of Two Arrays (#7)
Тип: HashMap / Set Сложность: easy Временная сложность: O(N + M) Пространственная сложность: O(N + M) - Ссылка: https://leetcode.com/problems/find-the-difference-of-two-arrays/
1 parent 586d6a4 commit 28cc996

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

‎src/hashmap_set/__init__.py

Whitespace-only changes.

‎src/hashmap_set/find_the_difference_of_two_arrays/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:
6+
set1 = set(nums1)
7+
set2 = set(nums2)
8+
9+
ans1 = set(num for num in nums1 if num not in set2)
10+
ans2 = set(num for num in nums2 if num not in set1)
11+
12+
return [list(ans1), list(ans2)]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
from src.hashmap_set.find_the_difference_of_two_arrays.solution import Solution
3+
4+
5+
@pytest.mark.parametrize(
6+
"nums1, nums2, expected",
7+
[([1, 2, 3], [2, 4, 6], [[1, 3], [4, 6]]), ([1, 2, 3, 3], [1, 1, 2, 2], [[3], []])],
8+
)
9+
def test_find_the_difference_of_two_arrays(nums1, nums2, expected):
10+
solution = Solution()
11+
assert solution.findDifference(nums1, nums2) == expected

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /