File tree 2 files changed +17
-14
lines changed
2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change 16
16
17
17
### 제출 일자
18
18
19
- 2024년 07월 31일 18:26:40
19
+ 2024년 07월 31일 18:27:14
20
20
21
21
### 문제 설명
22
22
Original file line number Diff line number Diff line change 1
1
import java .util .*;
2
2
class Solution {
3
3
public String solution (String [] cards1 , String [] cards2 , String [] goal ) {
4
- ArrayList <String > car1 = new ArrayList <>(Arrays .asList (cards1 ));
5
- ArrayList <String > car2 = new ArrayList <>(Arrays .asList (cards2 ));
6
-
7
- for (String str : goal ){
8
- if (!car1 .isEmpty () && str .equals (car1 .get (0 ))){
9
- car1 .remove (car1 .get (0 ));
4
+ String answer = "" ;
5
+ int [] arr = new int [goal .length ];
6
+ for (int i = 0 ; i <goal .length ; i ++){
7
+ for (int j = 0 ; j <cards1 .length ; j ++){
8
+ if (cards1 [j ].equals (goal [i ])) arr [i ] = j ;
10
9
}
11
- else if (!car2 .isEmpty () && str .equals (car2 .get (0 ))){
12
- car2 .remove (car2 .get (0 ));
13
- }
14
- else {
15
- return "No" ;
10
+ for (int j = 0 ; j <cards2 .length ; j ++){
11
+ if (cards2 [j ].equals (goal [i ])) arr [i ] = j ;
16
12
}
13
+
14
+ }
15
+ boolean check = true ;
16
+ for (int i = 0 ; i <arr .length -1 ; i ++){
17
+ if (arr [i ]!=arr [i +1 ] && arr [i ]!=arr [i +1 ]-1 ) check = false ;
18
+
17
19
}
18
- return "Yes" ;
19
-
20
+
21
+ if (check ) return "Yes" ;
22
+ else return "No" ;
20
23
}
21
24
}
You can’t perform that action at this time.
0 commit comments