FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
hackerrank-java/src/JavaList.java at master · anishLearnsToCode/hackerrank-java · GitHub
anishLearnsToCode
/
hackerrank-java
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
8
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
hackerrank-java
/
src
/
JavaList.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (35 loc) · 1.17 KB
Breadcrumbs
hackerrank-java
/
src
/
JavaList.java
Copy path
File metadata and controls
41 lines (35 loc) · 1.17 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
// https://www.hackerrank.com/challenges/java-list/problem
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
Scanner
;
public
class
JavaList
{
private
static
final
Scanner
SCANNER
=
new
Scanner
(
System
.
in
);
public
static
void
main
(
String
[]
args
) {
int
length
=
SCANNER
.
nextInt
();
List
<
Integer
>
list
=
new
ArrayList
<>();
for
(
int
index
=
0
;
index
<
length
;
index
++) {
list
.
add
(
SCANNER
.
nextInt
());
}
int
queries
=
SCANNER
.
nextInt
();
runQueries
(
queries
,
list
);
print
(
list
);
}
private
static
void
print
(
List
<
Integer
>
list
) {
for
(
int
element
:
list
) {
System
.
out
.
print
(
element
+
" "
);
}
}
private
static
void
runQueries
(
int
queries
,
List
<
Integer
>
list
) {
while
(
queries
-- >
0
) {
String
action
=
SCANNER
.
next
();
if
(
action
.
equals
(
"Insert"
)) {
int
index
=
SCANNER
.
nextInt
();
int
value
=
SCANNER
.
nextInt
();
list
.
add
(
index
,
value
);
}
else
{
// "Delete"
int
index
=
SCANNER
.
nextInt
();
list
.
remove
(
index
);
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL