-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSolution8.java
More file actions
42 lines (33 loc) · 935 Bytes
/
Solution8.java
File metadata and controls
42 lines (33 loc) · 935 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
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.IOException;
import java.util.Scanner;
public class Solution8 {
/*
* Complete the canModify function below.
*/
static String canModify(int[] a) {
/*
* Write your code here.
*/
boolean modified = false;
String result = "";
for(int i = 0 ;i < a.length - 1; i++){
if(a[i+1] < a[i]){
if(!modified) {
a[i + 1] = a[i] + 1;
modified = true;
result = "YES";
}
else{
result = "NO";
}
}
}
return result;
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int[] a = {5, 7, 7, 11, 15, 22, 24};
String result = canModify(a);
System.out.println(result);
}
}