FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interviews/leetcode/array/ContainsDuplicatesII.java at master · codingOnGithub/interviews · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
codingOnGithub
/
interviews
Public
forked from
kdn251/interviews
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
interviews
/
leetcode
/
array
/
ContainsDuplicatesII.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
18 lines (16 loc) · 676 Bytes
Breadcrumbs
interviews
/
leetcode
/
array
/
ContainsDuplicatesII.java
Copy path
File metadata and controls
18 lines (16 loc) · 676 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
//Given an array of integers and an integer k, find out whether there are two distinct indices i and
//j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
class
ContainsDuplicatesII
{
public
boolean
containsNearbyDuplicate
(
int
[]
nums
,
int
k
) {
HashMap
<
Integer
,
Integer
>
map
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
i
=
0
;
i
<
nums
.
length
;
i
++) {
int
current
=
nums
[
i
];
if
(
map
.
containsKey
(
current
) &&
i
-
map
.
get
(
current
) <=
k
) {
return
true
;
}
else
{
map
.
put
(
current
,
i
);
}
}
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL