FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Data-Structures-Algorithms/Array/MissingNumber.java at master · Java-aid/Data-Structures-Algorithms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Java-aid
/
Data-Structures-Algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
15
Star
12
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Data-Structures-Algorithms
/
Array
/
MissingNumber.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (25 loc) · 728 Bytes
Breadcrumbs
Data-Structures-Algorithms
/
Array
/
MissingNumber.java
Copy path
File metadata and controls
29 lines (25 loc) · 728 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
/**
* @author Kanahaiya Gupta
*
*/
public
class
MissingNumber
{
public
static
int
getMissingNumber
(
int
numbers
[],
int
n
) {
int
expectedSum
=
n
* (
n
+
1
) /
2
;
int
actualSum
=
0
;
for
(
int
number
:
numbers
) {
actualSum
=
actualSum
+
number
;
}
int
missingNo
=
expectedSum
-
actualSum
;
return
missingNo
;
}
public
static
void
main
(
String
[]
args
) {
int
numbers1
[] = {
6
,
3
,
2
,
4
,
1
,
7
,
5
,
10
,
8
};
int
n1
=
10
;
int
missingNumber1
=
getMissingNumber
(
numbers1
,
n1
);
System
.
out
.
println
(
"Output 1: "
+
missingNumber1
);
int
numbers2
[] = {
2
,
3
,
1
,
5
};
int
n2
=
5
;
int
missingNumber2
=
getMissingNumber
(
numbers2
,
n2
);
System
.
out
.
println
(
"Output 2: "
+
missingNumber2
);
}
}
Back
|
FazBrowse Home
|
New Git URL