1
1
package g3601_3700 .s3690_split_and_merge_array_transformation ;
2
2
3
3
// #Medium #Array #Hash_Table #Breadth_First_Search #Weekly_Contest_468
4
- // #2025_09_25_Time_11_ms_(99.81 %)_Space_45.46_MB_(45.98 %)
4
+ // #2025_09_26_Time_9_ms_(100.00 %)_Space_45.05_MB_(91.32 %)
5
5
6
6
import java .util .Deque ;
7
7
import java .util .HashMap ;
@@ -13,9 +13,9 @@ public int minSplitMerge(int[] nums1, int[] nums2) {
13
13
int n = nums1 .length ;
14
14
int id = 0 ;
15
15
Map <Integer , Integer > map = new HashMap <>(n << 1 );
16
- for (int i = 0 ; i < n ; i ++ ) {
17
- if (!map .containsKey (nums1 [ i ] )) {
18
- map .put (nums1 [ i ] , id ++);
16
+ for (int value : nums1 ) {
17
+ if (!map .containsKey (value )) {
18
+ map .put (value , id ++);
19
19
}
20
20
}
21
21
int source = 0 ;
@@ -39,30 +39,6 @@ public int minSplitMerge(int[] nums1, int[] nums2) {
39
39
for (int i = 0 ; i < n ; i ++) {
40
40
for (int j = i ; j < n ; j ++) {
41
41
for (int k = -1 ; k < n ; k ++) {
42
- if (k < i - 1 ) {
43
- int [] ncur = new int [n ];
44
- int t1 = 0 ;
45
- for (int t = 0 ; t <= k ; t ++) {
46
- ncur [t1 ++] = cur [t ];
47
- }
48
- for (int t = i ; t <= j ; t ++) {
49
- ncur [t1 ++] = cur [t ];
50
- }
51
- for (int t = k + 1 ; t < i ; t ++) {
52
- ncur [t1 ++] = cur [t ];
53
- }
54
- for (int t = j + 1 ; t < n ; t ++) {
55
- ncur [t1 ++] = cur [t ];
56
- }
57
- int t2 = hash (ncur );
58
- if (distances [t2 ] == 0 ) {
59
- distances [t2 ] = distances [x ] + 1 ;
60
- if (t2 == target ) {
61
- return distances [x ];
62
- }
63
- que .add (t2 );
64
- }
65
- }
66
42
if (k > j ) {
67
43
int [] ncur = new int [n ];
68
44
int t1 = 0 ;
0 commit comments