leetcode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example 1:
Input: nums1 = , nums2 =
Output:
Example 2:
Input: nums1 = , nums2 =
Output:
Note:
Each element in the result must be unique.
The result can be in any order.
import java.util.Arrays;
class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i :nums1){
if(i < min) min = i;
if(i > max) max = i;
}
boolean[] table = new boolean;
for(int s : nums1) table = true;
int[] temp = new int;
int size = 0;
for(int j :nums2){
if(j <= max && j >= min && table){
temp = j;
table = false;
}
}
int[] res = new int;
for(int m =0 ; m < size; m++)res = temp;
return res;
}
}
页:
[1]