FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Algorithm-Solutions-Java/ArraySorting/MinDiff.java at master · ManojKumarPatnaik/Algorithm-Solutions-Java · GitHub
ManojKumarPatnaik
/
Algorithm-Solutions-Java
Public
forked from
theprogrammedwords/Algorithm-Solutions-Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
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-Solutions-Java
/
ArraySorting
/
MinDiff.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (41 loc) · 1.05 KB
Breadcrumbs
Algorithm-Solutions-Java
/
ArraySorting
/
MinDiff.java
Copy path
File metadata and controls
56 lines (41 loc) · 1.05 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*Problem Description
Find the minimum difference possible between any two elements in the given array.
Input format
First line will contain a single integer n representing the size of the array.
Second line will contain n space separated integers representing the array.
Output format
Output the answer in single line.
Sample Input 1
3
1 2 4
Sample Output 1
1
Explanation 1
2 - 1 = 1 minimum difference
Constraints
2<=n<=100000
1<=A[i]<=1000000000
*/
import
java
.
util
.*;
class
MinDiff
{
public
static
void
main
(
String
args
[]) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
int
a
[] =
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++) {
a
[
i
] =
sc
.
nextInt
();
}
int
res
=
minDiff
(
n
,
a
);
System
.
out
.
println
(
res
);
}
static
int
minDiff
(
int
n
,
int
a
[]) {
int
mini
=
Integer
.
MAX_VALUE
;
Arrays
.
sort
(
a
);
for
(
int
i
=
0
;
i
<
a
.
length
-
1
;
i
++){
if
(
mini
>
a
[
i
+
1
]-
a
[
i
]){
mini
=
a
[
i
+
1
]-
a
[
i
];
}
}
return
mini
;
}
}
Back
|
FazBrowse Home
|
New Git URL