Repository navigation
Expand file tree
/
Copy pathEast3_2.java
More file actions
90 lines (66 loc) · 1.67 KB
/
Copy pathEast3_2.java
File metadata and controls
90 lines (66 loc) · 1.67 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package Test;
import java.util.*;
public class East3 {
public static int solution(int[] A) {
int answer = 0;
boolean chk = true;
for (int i = 0; i < A.length - 2; i++) {
if (A[i] > A[i + 1] && A[i + 1] < A[i + 2] || A[i] < A[i + 1] && A[i + 1] > A[i + 2]) {
// 121 또는 212 가 만족하면
} else {
chk = false; // 한번이라도 아니면 false
}
}
if (chk == true) {
return answer;
}
//한번에 끝나면 return으로 0 반환하고 나감
//하나씩 빼야하는 경우
int k = 0; //몇번 돌지 체크해주기 위해
while (k != A.length) {
System.out.println(k + " k " + answer);
ArrayList<Integer> list = new ArrayList<Integer>();
// boolean chk = true;
for (int j = 0; j < A.length; j++) {
if (j == k) {
continue;
}
list.add(A[j]);
}
System.out.println(list);
System.out.println();
chk = false;
for (int l = 0; l < list.size() - 2; l++) {
if (list.get(l) > list.get(l + 1) && list.get(l + 1) < list.get(l + 2)
|| list.get(l) < list.get(l + 1) && list.get(l + 1) > list.get(l + 2)) {
System.out.println("엘 " + l);
chk = true;
} else {
chk = false;
break;
}
}
System.out.println(chk);
if (chk == true) {
answer++;
}
k++;
}
if (chk == false && answer == 0)
{
answer = -1;
}
System.out.println(chk);
System.out.println(answer);
return answer;
}
public static void main(String[] args) {
int arr1[] = { 3, 4, 5, 3, 7 };
int arr2[] = { 1, 2, 3, 4 };
int arr3[] = { 1, 3, 1, 2 };
int arr4[] = { 3, 5, 5, 2, 1 };
int arr5[] = { 5, 5, 4, 2, 6 };
int arr7[] = { 6, 7, 2, 5, 7 };
solution(arr5);
}
}