FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode349.java at master · Edwardlinge/JavaArithmetic · GitHub
Edwardlinge
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode349.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (22 loc) · 746 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode349.java
Copy path
File metadata and controls
31 lines (22 loc) · 746 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package
LeetCode
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
TreeSet
;
public
class
LeetCode349
{
// https://leetcode.com/problems/intersection-of-two-arrays/description/
// 时间复杂度: O(nlogn)
// 空间复杂度: O(n)
public
int
[]
intersection
(
int
[]
nums1
,
int
[]
nums2
) {
HashSet
<
Integer
>
record
=
new
HashSet
<
Integer
>();
for
(
int
num
:
nums1
)
record
.
add
(
num
);
HashSet
<
Integer
>
resultSet
=
new
HashSet
<
Integer
>();
for
(
int
num
:
nums2
)
if
(
record
.
contains
(
num
))
resultSet
.
add
(
num
);
int
[]
res
=
new
int
[
resultSet
.
size
()];
int
index
=
0
;
for
(
Integer
num
:
resultSet
)
res
[
index
++] =
num
;
return
res
;
}
}
Back
|
FazBrowse Home
|
New Git URL