1 Star 0 Fork 0

Neo_1001/LeetCode刷题记录

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
LC_349.java 899 Bytes
Copy Edit Raw Blame History
Neo_1001 authored 2024-04-10 22:16 . first commit
package LeetCode;
import java.util.ArrayList;
import java.util.HashSet;
public class LC_349 {
public static void main(String[] args) {
}
public static int[] intersection(int[] nums1, int[] nums2) {
HashSet<Integer> set1 = new HashSet<>();
HashSet<Integer> set2 = new HashSet<>();
for (int i = 0; i < nums1.length; i++) {
set1.add(nums1[i]);
}
for (int i = 0; i < nums2.length; i++) {
set2.add(nums2[i]);
}
ArrayList<Integer> sam = new ArrayList<>();
for (Integer integer : set1) {
int cont = 0;
if (set2.contains(integer)) {
sam.add(integer);
}
}
int size = sam.size();
int[] sam1 = new int[size];
for (int i = 0; i < sam1.length; i++) {
sam1[i] = sam.get(i);
}
return sam1;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/neo1001/leet-code-practice-record.git
git@gitee.com:neo1001/leet-code-practice-record.git
neo1001
leet-code-practice-record
LeetCode刷题记录
master

Search