4
9
5
9
4
[0][1][2][3][4]
nums2
9
4
9
8
4
[0][1][2][3][4]
Brute force · nested loops
▸1result ← []2for x in nums1: for y in nums2:3 if x == y and x not in result: result.append(x)4return result
state
- result[]
warming up the animation
Given two integer arrays, return an array of their intersection. Each value in the result must appear only once, and the order does not matter.
▸1result ← []2for x in nums1: for y in nums2:3 if x == y and x not in result: result.append(x)4return result
line 1Check every value of the first array against every value of the second, and remember to avoid adding anything twice.