Skip to content

Commit 08fb893

Browse files
author
Yafiaha
committed
Feat: Yafiah Lesson_11 extra credit TS solutions
1 parent fac971b commit 08fb893

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@
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: number[] = new Array(2 * n);
8+
for (let i = 0; i < n; i++) {
9+
ans[i] = nums[i];
10+
ans[n + i] = 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 list: number[] = [];
21+
for (let i = 0; i < words.length; i++) {
22+
const str = words[i];
23+
for (let j = 0; j < str.length; j++) {
24+
if (str.charAt(j) === x) {
25+
list.push(i);
26+
break;
27+
}
28+
}
29+
}
30+
return list;
1531
}

0 commit comments

Comments
 (0)