Skip to content

Commit 3c14dba

Browse files
committed
feat: added lesson 11 solutions and extra credit for Chelsea
1 parent 8ee965f commit 3c14dba

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
Lines changed: 17 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,28 @@ public class Lesson11 {
910
* https://leetcode.com/problems/concatenation-of-array
1011
*/
1112
public int[] getConcatenation(int[] nums) {
12-
return null;
13+
int n = nums.length;
14+
int[] ans = new int[2 * n];
15+
16+
for (int i = 0; i < nums.length; i++){
17+
ans[i] = nums[i];
18+
ans[i + n] = nums[i];
19+
}
20+
return ans;
1321
}
1422

1523
/**
1624
* Provide the solution to LeetCode 2942 here:
1725
* https://leetcode.com/problems/find-words-containing-character/
1826
*/
1927
public List<Integer> findWordsContaining(String[] words, char x) {
20-
return null;
28+
List<Integer> indices = new ArrayList<>();
29+
30+
for (int i = 0; i < words.length; i++) {
31+
if (words[i].indexOf(x) != -1) {
32+
indices.add(i);
33+
}
34+
}
35+
return indices;
2136
}
2237
}

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
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+
9+
for (let i = 0; i < n; i++) {
10+
ans[i] = nums[i];
11+
ans[i + n] = nums[i];
12+
}
13+
return ans;
714
}
815

916
/**
1017
* Provide the solution to LeetCode 2942 here:
1118
* https://leetcode.com/problems/find-words-containing-character/
1219
*/
1320
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
21+
const indices: number[] = [];
22+
23+
for (let i = 0; i < words.length; i++) {
24+
if (words[i].includes(x)) {
25+
indices.push(i);
26+
}
27+
}
28+
return indices;
1529
}

0 commit comments

Comments
 (0)