Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2]
.
class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ re = [] n = 0 for i in range(len(nums1)): n |= 1<<nums1[i] for i in range(len(nums2)): if n&(1<<nums2[i]): n &= (~(1<<nums2[i])) re.append(nums2[i]) return re
相关推荐
intersection of two arrays 350: intersection of two arrays ii medium 33: search in sorted array 81: search in rotated sorted array ii 153: find minimum in rotated sorted array 162: find peak element ...
Array is Sorted 167 125 344 345 11 1-5 滑动窗口 Minimum Size Subarray Sum 209 3 438 76 第二章 查找表相关问题 2-1 set的使用 Intersection of Two Arrays 349 2-2 map的使用 Intersection of Two Arrays II ...
Intersection of Two Arrays 17.10. Find Majority Element LCCI Game of Life Find All Numbers Disappeared in an Array Shortest Unsorted Continuous Subarray Rotate Image 宝石与石头Jewels and Stones Kids ...
leetcode中国大批 ...Intersection of the two sorted arrays. 7. Write a program to cyclically rotate an array by one. 8. find Largest sum contiguous Subarray [V. IMP] 9* Minimise the maximum
leetcode中国Final450_数据结构 实际上,这个存储库包含...Intersection of the two sorted arrays. *Write a program to cyclically rotate an array by one. *find Largest sum contiguous Subarray [V. IMP] *Minimi
/* finds the intersection of * two arrays in a simple fashion. * * PARAMS * a - first array, must already be sorted * b - second array, must already be sorted * * NOTES * * Should have O(n) ...
421 | [Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [C++](./C++/maximum-xor-of-two-numbers-in-an-array.cpp) [Python](./Python/...
1.8 Finding the Intersection of Two Dictionaries 1.9 Assigning and Testing with One Statement 1.10 Using List Comprehensions Instead of map and filter 1.11 Unzipping Simple List-Like Objects ...
A speaker recognition system includes two primary components: a front-end and a back-end. The front-end transforms acoustic waveforms into more compact and less redundant representations called ...
MESSAGE Modifies the faces of a body by the use of various methods. HINT This command is superseded by Synchronous Modeling commands. To run this legacy command, set UGII_DMX_NX502=1. HELP DSN_face...