Skip to content

Commit 4180d4f

Browse files
committed
feat: add typescript solution to lc problem: No.220
No.2200.Find All K-Distant Indices in an Array
1 parent 73e7049 commit 4180d4f

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

solution/2200-2299/2200.Find All K-Distant Indices in an Array/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,20 @@
7373
### **TypeScript**
7474

7575
```ts
76-
76+
function findKDistantIndices(nums: number[], key: number, k: number): number[] {
77+
const n = nums.length;
78+
let ans = [];
79+
for (let j = 0; j < n; j++) {
80+
if (nums[j] == key) {
81+
for (let i = j - k; i <= j + k; i++) {
82+
if (i >= 0 && i < n && !ans.includes(i)) {
83+
ans.push(i);
84+
}
85+
}
86+
}
87+
}
88+
return ans;
89+
};
7790
```
7891

7992
### **...**

solution/2200-2299/2200.Find All K-Distant Indices in an Array/README_EN.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,20 @@ Hence, we return [0,1,2,3,4].
6363
### **TypeScript**
6464

6565
```ts
66-
66+
function findKDistantIndices(nums: number[], key: number, k: number): number[] {
67+
const n = nums.length;
68+
let ans = [];
69+
for (let j = 0; j < n; j++) {
70+
if (nums[j] == key) {
71+
for (let i = j - k; i <= j + k; i++) {
72+
if (i >= 0 && i < n && !ans.includes(i)) {
73+
ans.push(i);
74+
}
75+
}
76+
}
77+
}
78+
return ans;
79+
};
6780
```
6881

6982
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function findKDistantIndices(nums: number[], key: number, k: number): number[] {
2+
const n = nums.length;
3+
let ans = [];
4+
for (let j = 0; j < n; j++) {
5+
if (nums[j] == key) {
6+
for (let i = j - k; i <= j + k; i++) {
7+
if (i >= 0 && i < n && !ans.includes(i)) {
8+
ans.push(i);
9+
}
10+
}
11+
}
12+
}
13+
return ans;
14+
};

0 commit comments

Comments
 (0)