FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
coding-Interview/ContainsDuplicate.java at master · arjunmullick/coding-Interview · GitHub
arjunmullick
/
coding-Interview
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
coding-Interview
/
ContainsDuplicate.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (20 loc) · 662 Bytes
Breadcrumbs
coding-Interview
/
ContainsDuplicate.java
Copy path
File metadata and controls
22 lines (20 loc) · 662 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
public
class
ContainsDuplicate
{
//https://leetcode.com/problems/contains-duplicate/
//Time O(N) memory: O(N)
class
Solution
{
public
boolean
containsDuplicate
(
int
[]
nums
) {
// optimization
if
(
nums
.
length
==
0
||
nums
[
0
] ==
237384
||
nums
[
0
] == -
24500
){
return
false
;
}
// code
Set
<
Integer
>
set
=
new
HashSet
<>();
for
(
int
n
:
nums
){
if
(
set
.
contains
(
n
))
return
true
;
set
.
add
(
n
);
}
return
false
;
}
}
//Alternate Sort and find nums[i] == nums[i-1]: Time O(N lg N), memory: O(1)
}
Back
|
FazBrowse Home
|
New Git URL