Skip to content

Commit cf29215

Browse files
committed
feat: add lesson 11 solutions for Tommy Tran
1 parent 8ee965f commit cf29215

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codedifferently.lesson11;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
public class Lesson11 {
@@ -9,14 +10,26 @@ public class Lesson11 {
910
* https://leetcode.com/problems/concatenation-of-array
1011
*/
1112
public int[] getConcatenation(int[] nums) {
12-
return null;
13+
int[] ans = new int[nums.length * 2];
14+
15+
for (int i = 0; i < nums.length; i++) {
16+
ans[i] = nums[i];
17+
ans[i + nums.length] = nums[i];
18+
}
19+
return ans;
1320
}
1421

1522
/**
1623
* Provide the solution to LeetCode 2942 here:
1724
* https://leetcode.com/problems/find-words-containing-character/
1825
*/
1926
public List<Integer> findWordsContaining(String[] words, char x) {
20-
return null;
27+
List<Integer> indices = new ArrayList<>();
28+
for (int i = 0; i < words.length; i++) {
29+
if (words[i].contains(String.valueOf(x))) {
30+
indices.add(i);
31+
}
32+
}
33+
return indices;
2134
}
2235
}

lesson_11/arrays_ts/src/lesson11.ts

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

914
/**
1015
* Provide the solution to LeetCode 2942 here:
1116
* https://leetcode.com/problems/find-words-containing-character/
1217
*/
1318
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
19+
const indices: number[] = [];
20+
for (let i = 0; i < words.length; i++) {
21+
if (words[i].includes(x)) {
22+
indices.push(i);
23+
}
24+
}
25+
return indices;
1526
}

0 commit comments

Comments
 (0)