Skip to content

Commit 548f5f9

Browse files
committed
Feat: before hw explained, TS conversion of Concatenation and Find words
1 parent 55e57eb commit 548f5f9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
* https://leetcode.com/problems/concatenation-of-array
44
*/
55
export function getConcatenation(nums: number[]): number[] {
6-
return [];
6+
const n = nums.length;
7+
const ans = new Array(2 * n);
8+
for (let i = 0; i < n; i++) {
9+
ans[i] = nums[i];
10+
ans[i + n] = nums[i];
11+
}
12+
return ans;
713
}
814

915
/**
1016
* Provide the solution to LeetCode 2942 here:
1117
* https://leetcode.com/problems/find-words-containing-character/
1218
*/
1319
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
20+
const indices: number[] = [];
21+
for (let i = 0; i < words.length; i++) {
22+
if (words[i].includes(x)) {
23+
indices.push(i);
24+
}
25+
}
26+
return indices;
1527
}

0 commit comments

Comments
 (0)