-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJolly.java
More file actions
29 lines (27 loc) · 836 Bytes
/
Copy pathJolly.java
File metadata and controls
29 lines (27 loc) · 836 Bytes
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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Jolly {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
list.add(x);
}
ArrayList<Integer> sub = new ArrayList<Integer>();
for (int i = 0; i < n - 1; i++) {
sub.add(Math.abs(list.get(i + 1) - list.get(i)));
}
Collections.sort(sub);
for (int i = 0; i < n - 1; i++) {
if (sub.get(i) != i + 1) {
System.out.println("Not jolly");
return;
}
}
System.out.println("Jolly");
return;
}
}