File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .gatsby ;
2+
3+ import java .util .HashMap ;
4+ import java .util .List ;
5+ import java .util .Map ;
6+
7+ /**
8+ * @classname _1640CheckArrayFormationThroughConcatenation
9+ * @description:
10+ * @author: gatsby
11+ * @create: 2022/9/22
12+ **/
13+ public class _1640CheckArrayFormationThroughConcatenation {
14+ public boolean canFormArray (int [] arr , int [][] pieces ) {
15+ Map <Integer , int []> map = new HashMap <>();
16+
17+ for (int [] piece : pieces ) {
18+ map .put (piece [0 ], piece );
19+ }
20+
21+ for (int i = 0 ; i < arr .length ; ) {
22+ if (!map .containsKey (arr [i ])) return false ;
23+ int [] array = map .get (arr [i ]);
24+ for (int j = 0 ; j < array .length ; ++j , ++i ) {
25+ if (arr [i ] != array [j ]) return false ;
26+ }
27+ }
28+ return true ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments