Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-05-03 15:52:37
https://leetcode.com/problems/find-the-difference-of-two-arrays/description/
2215. Find the Difference of Two Arrays
给你两个阵列分别回传该两个阵列与另外一个阵列不同的不重复元素。
Example 1:
Input: nums1 = [1,2,3], nums2 = [2,4,6]
Output: [[1,3],[4,6]]
Explanation:
For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1
and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4
and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].
Example 2:
Input: nums1 = [1,2,3,3], nums2 = [1,1,2,2]
Output: [[3],[]]
Explanation:
For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] ==
nums1[3], their value is only included once and answer[0] = [3].
Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
思路:
1.用一个Set纪录另一个阵列的元素并和当前阵列作比较,如果没出现在另一个set就加入
结果集。
2.分别做两次就好。
Java Code:
作者: ken1990710 (沙茶花养的饲育员)   2023-05-03 15:53:00
大师
作者: Che31128 (justjoke)   2023-05-03 15:56:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com