Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f1171f

Browse files
authored
feat: add solutions to lc problem: No.1497 (doocs#3596)
1 parent feac470 commit 3f1171f

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,42 @@ func canArrange(arr []int, k int) bool {
145145
}
146146
```
147147

148+
#### TypeScript
149+
150+
```ts
151+
function canArrange(arr: number[], k: number): boolean {
152+
const cnt = Array(k).fill(0);
153+
154+
for (const x of arr) {
155+
cnt[((x % k) + k) % k]++;
156+
}
157+
158+
for (let i = 1; i < k; i++) {
159+
if (cnt[i] !== cnt[k - i]) return false;
160+
}
161+
162+
return cnt[0] % 2 === 0;
163+
}
164+
```
165+
166+
#### JavaScript
167+
168+
```js
169+
function canArrange(arr, k) {
170+
const cnt = Array(k).fill(0);
171+
172+
for (const x of arr) {
173+
cnt[((x % k) + k) % k]++;
174+
}
175+
176+
for (let i = 1; i < k; i++) {
177+
if (cnt[i] !== cnt[k - i]) return false;
178+
}
179+
180+
return cnt[0] % 2 === 0;
181+
}
182+
```
183+
148184
<!-- tabs:end -->
149185

150186
<!-- solution:end -->

solution/1400-1499/1497.Check If Array Pairs Are Divisible by k/README_EN.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,42 @@ func canArrange(arr []int, k int) bool {
137137
}
138138
```
139139

140+
#### TypeScript
141+
142+
```ts
143+
function canArrange(arr: number[], k: number): boolean {
144+
const cnt = Array(k).fill(0);
145+
146+
for (const x of arr) {
147+
cnt[((x % k) + k) % k]++;
148+
}
149+
150+
for (let i = 1; i < k; i++) {
151+
if (cnt[i] !== cnt[k - i]) return false;
152+
}
153+
154+
return cnt[0] % 2 === 0;
155+
}
156+
```
157+
158+
#### JavaScript
159+
160+
```js
161+
function canArrange(arr, k) {
162+
const cnt = Array(k).fill(0);
163+
164+
for (const x of arr) {
165+
cnt[((x % k) + k) % k]++;
166+
}
167+
168+
for (let i = 1; i < k; i++) {
169+
if (cnt[i] !== cnt[k - i]) return false;
170+
}
171+
172+
return cnt[0] % 2 === 0;
173+
}
174+
```
175+
140176
<!-- tabs:end -->
141177

142178
<!-- solution:end -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function canArrange(arr, k) {
2+
const cnt = Array(k).fill(0);
3+
4+
for (const x of arr) {
5+
cnt[((x % k) + k) % k]++;
6+
}
7+
8+
for (let i = 1; i < k; i++) {
9+
if (cnt[i] !== cnt[k - i]) return false;
10+
}
11+
12+
return cnt[0] % 2 === 0;
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function canArrange(arr: number[], k: number): boolean {
2+
const cnt = Array(k).fill(0);
3+
4+
for (const x of arr) {
5+
cnt[((x % k) + k) % k]++;
6+
}
7+
8+
for (let i = 1; i < k; i++) {
9+
if (cnt[i] !== cnt[k - i]) return false;
10+
}
11+
12+
return cnt[0] % 2 === 0;
13+
}

0 commit comments

Comments
 (0)