Skip to content

Commit 5db77f9

Browse files
committed
feat: add js solution to lc problem: No.1460
1 parent 25b1519 commit 5db77f9

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ function canBeEqual(target: number[], arr: number[]): boolean {
283283
}
284284
```
285285

286+
#### JavaScript
287+
288+
```js
289+
function canBeEqual(target, arr) {
290+
const n = target.length;
291+
const cnt = Array(1001).fill(0);
292+
for (let i = 0; i < n; i++) {
293+
cnt[target[i]]++;
294+
cnt[arr[i]]--;
295+
}
296+
return cnt.every(v => !v);
297+
}
298+
```
299+
286300
#### Rust
287301

288302
```rust

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ function canBeEqual(target: number[], arr: number[]): boolean {
281281
}
282282
```
283283

284+
#### JavaScript
285+
286+
```js
287+
function canBeEqual(target, arr) {
288+
const n = target.length;
289+
const cnt = Array(1001).fill(0);
290+
for (let i = 0; i < n; i++) {
291+
cnt[target[i]]++;
292+
cnt[arr[i]]--;
293+
}
294+
return cnt.every(v => !v);
295+
}
296+
```
297+
284298
#### Rust
285299

286300
```rust
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function canBeEqual(target, arr) {
2+
const n = target.length;
3+
const cnt = Array(1001).fill(0);
4+
for (let i = 0; i < n; i++) {
5+
cnt[target[i]]++;
6+
cnt[arr[i]]--;
7+
}
8+
return cnt.every(v => !v);
9+
}

0 commit comments

Comments
 (0)