11package g3601_3700 .s3690_split_and_merge_array_transformation ;
22
33// #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 %)
55
66import java .util .Deque ;
77import java .util .HashMap ;
@@ -13,9 +13,9 @@ public int minSplitMerge(int[] nums1, int[] nums2) {
1313 int n = nums1 .length ;
1414 int id = 0 ;
1515 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 ++);
1919 }
2020 }
2121 int source = 0 ;
@@ -39,30 +39,6 @@ public int minSplitMerge(int[] nums1, int[] nums2) {
3939 for (int i = 0 ; i < n ; i ++) {
4040 for (int j = i ; j < n ; j ++) {
4141 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- }
6642 if (k > j ) {
6743 int [] ncur = new int [n ];
6844 int t1 = 0 ;
0 commit comments