Skip to content

Commit 9e8e4d2

Browse files
committed
feat: add python and java solutions to leetcode problem: No.1460
1460. Make Two Arrays Equal by Reversing Sub-arrays
1 parent cf574fc commit 9e8e4d2

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

solution/1400-1499/1460.Make Two Arrays Equal by Reversing Sub-arrays/README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,34 @@
6565

6666
<!-- 这里可写通用的实现逻辑 -->
6767

68+
只要两数组元素均相同,那么就能通过翻转使得两个数组相等。
69+
70+
因此,对两数组进行排序,然后判断两数组是否相同即可。
71+
6872
<!-- tabs:start -->
6973

7074
### **Python3**
7175

7276
<!-- 这里可写当前语言的特殊实现逻辑 -->
7377

7478
```python
75-
79+
class Solution:
80+
def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
81+
return sorted(target) == sorted(arr)
7682
```
7783

7884
### **Java**
7985

8086
<!-- 这里可写当前语言的特殊实现逻辑 -->
8187

8288
```java
83-
89+
class Solution {
90+
public boolean canBeEqual(int[] target, int[] arr) {
91+
Arrays.sort(target);
92+
Arrays.sort(arr);
93+
return Arrays.equals(target, arr);
94+
}
95+
}
8496
```
8597

8698
### **...**

solution/1400-1499/1460.Make Two Arrays Equal by Reversing Sub-arrays/README_EN.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@ There are multiple ways to convert arr to target, this is not the only way to do
7070
### **Python3**
7171

7272
```python
73-
73+
class Solution:
74+
def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
75+
return sorted(target) == sorted(arr)
7476
```
7577

7678
### **Java**
7779

7880
```java
79-
81+
class Solution {
82+
public boolean canBeEqual(int[] target, int[] arr) {
83+
Arrays.sort(target);
84+
Arrays.sort(arr);
85+
return Arrays.equals(target, arr);
86+
}
87+
}
8088
```
8189

8290
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution {
2+
public boolean canBeEqual(int[] target, int[] arr) {
3+
Arrays.sort(target);
4+
Arrays.sort(arr);
5+
return Arrays.equals(target, arr);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
3+
return sorted(target) == sorted(arr)

0 commit comments

Comments
 (0)