Leetcode 3002. Maximum Size of a Set After Removals
3002. Maximum Size of a Set After RemovalsYou are given two 0-indexed integer arrays nums1 and nums2 of even length n. You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s. Return the maximum possible size of the set s. Example 1: 1234Input: nums1 = [1,2,1,2], nums2 = [1,1,1,1]Output: 2Explanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become e...
Leetcode 0454. 4Sum II
454. 4Sum IIGiven four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: 0 <= i, j, k, l < n nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0 Example 1: 123456Input: nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]Output: 2Explanation:The two tuples are:1. (0, 0, 0, 1) -> nums1[0] + nums2[0] + nums3[0] + nums4[1] = 1 + (-2) + (-1) + 2 = 02. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 +...
Leetcode 0349. Intersection of Two Arrays
349. Intersection of Two ArraysGiven two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Example 1: 12Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2] Example 2: 123Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [9,4]Explanation: [4,9] is also accepted. 题目大意给定两个整数数组 nums1 和 nums2,返回它们的交集。结果中的每个元素必须是唯一的,并且可以按任意顺序返回。 解题思路可以使用哈希集合来高效求解: 先将第一个数组中的元素存入一个哈希集合,自动去除重复元素 遍历第二个数组,检查每个元...

