-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1460.通过翻转子数组使两个数组相等.c
54 lines (37 loc) · 1.05 KB
/
1460.通过翻转子数组使两个数组相等.c
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
/*
* @lc app=leetcode.cn id=1460 lang=c
*
* [1460] 通过翻转子数组使两个数组相等
*/
// @lc code=start
bool canBeEqual(int* target, int targetSize, int* arr, int arrSize){
bool resultBool = true;
for (int i = 0; i < targetSize; i++) {
int targetIndex = i;
int arrIndex = i;
for (int j = (i + 1); j < targetSize; j++) {
if (target[targetIndex] > target[j]) {
targetIndex = j;
}
if (arr[arrIndex] > arr[j]) {
arrIndex = j;
}
}
if (targetIndex != i) {
target[targetIndex] ^= target[i];
target[i] ^= target[targetIndex];
target[targetIndex] ^= target[i];
}
if (arrIndex != i) {
arr[arrIndex] ^= arr[i];
arr[i] ^= arr[arrIndex];
arr[arrIndex] ^= arr[i];
}
if (arr[i] != target[i]) {
resultBool = false;
break;
}
}
return resultBool;
}
// @lc code=end