feat: 2025-10-28打卡
This commit is contained in:
32
350.intersection-of-two-arrays-ii.java
Normal file
32
350.intersection-of-two-arrays-ii.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @lc app=leetcode id=350 lang=java
|
||||
*
|
||||
* [350] Intersection of Two Arrays II
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class Solution {
|
||||
public int[] intersect(int[] nums1, int[] nums2) {
|
||||
Arrays.sort(nums1);
|
||||
Arrays.sort(nums2);
|
||||
int i = 0, j = 0;
|
||||
List<Integer> ret = new ArrayList<>();
|
||||
while(i<nums1.length && j < nums2.length) {
|
||||
if(nums1[i] == nums2[j]) {
|
||||
ret.add(nums1[i]);
|
||||
i++;
|
||||
j++;
|
||||
} else if(nums1[i] < nums2[j]) {
|
||||
i++;
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return ret.stream().mapToInt(f->f).toArray();
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user