FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_03/id_113/leetcode_373_113.java at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_03
/
id_113
/
leetcode_373_113.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (32 loc) · 1.18 KB
Breadcrumbs
algorithm
/
Week_03
/
id_113
/
leetcode_373_113.java
Copy path
File metadata and controls
35 lines (32 loc) · 1.18 KB
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
32
33
34
35
class
Solution
{
public
List
<
int
[]>
kSmallestPairs
(
int
[]
nums1
,
int
[]
nums2
,
int
k
) {
TreeMap
<
Integer
,
List
<
Integer
[]>>
tm
=
new
TreeMap
<>();
for
(
int
i
=
0
;
i
<
nums1
.
length
;
i
++) {
for
(
int
j
=
0
;
j
<
nums2
.
length
;
j
++) {
Integer
key
=
nums1
[
i
] +
nums2
[
j
];
List
<
Integer
[]>
list
=
tm
.
get
(
key
);
if
(
list
==
null
) {
list
=
new
ArrayList
();
tm
.
put
(
key
,
list
);
}
list
.
add
(
new
Integer
[]{
nums1
[
i
],
nums2
[
j
]});
}
}
List
<
int
[]>
list
=
new
ArrayList
();
Iterator
<
Map
.
Entry
<
Integer
,
List
<
Integer
[]>>>
it
=
tm
.
entrySet
().
iterator
();
int
c
=
0
;
while
(
it
.
hasNext
()) {
if
(
c
==
k
)
break
;
Map
.
Entry
<
Integer
,
List
<
Integer
[]>>
entry
=
it
.
next
();
List
<
Integer
[]>
coords
=
entry
.
getValue
();
Iterator
<
Integer
[]>
it2
=
coords
.
iterator
();
while
(
it2
.
hasNext
()) {
Integer
[]
coord
=
it2
.
next
();
list
.
add
(
new
int
[]{
coord
[
0
],
coord
[
1
]});
++
c
;
if
(
c
==
k
)
break
;
}
}
return
list
;
}
}
Back
|
FazBrowse Home
|
New Git URL