Skip to content

Commit b2084eb

Browse files
committed
lesson_11_homework
1 parent 7b3bd25 commit b2084eb

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
package com.codedifferently.lesson11;
22

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

56
public class Lesson11 {
67

78
/**
8-
* Provide the solution to LeetCode 1929 here:
9+
* Solution to LeetCode problem: Concatenation of Array
910
* https://leetcode.com/problems/concatenation-of-array
1011
*/
1112
public int[] getConcatenation(int[] nums) {
12-
return null;
13+
int size = nums.length;
14+
15+
int[] result = new int[size * 2];
16+
17+
for (int i = 0; i < size * 2; i++) {
18+
result[i] = nums[i % size];
19+
}
20+
21+
return result;
1322
}
1423

1524
/**
16-
* Provide the solution to LeetCode 2942 here:
25+
* Solution to LeetCode problem: Find Words Containing Character
1726
* https://leetcode.com/problems/find-words-containing-character/
1827
*/
1928
public List<Integer> findWordsContaining(String[] words, char x) {
20-
return null;
29+
List<Integer> result = new ArrayList<>();
30+
31+
String searchChar = String.valueOf(x);
32+
33+
for (int i = 0; i < words.length; i++) {
34+
if (words[i].contains(searchChar)) {
35+
result.add(i);
36+
}
37+
}
38+
39+
return result;
2140
}
2241
}

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* https://leetcode.com/problems/concatenation-of-array
44
*/
55
export function getConcatenation(nums: number[]): number[] {
6-
return [];
6+
return [...nums, ... nums];
77
}
88

99
/**
1010
* Provide the solution to LeetCode 2942 here:
1111
* https://leetcode.com/problems/find-words-containing-character/
1212
*/
1313
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
14+
return words
15+
.map((word, index) => (word.includes(x) ? index : -1))
16+
.filter(index => index !== -1);
1517
}

0 commit comments

Comments
 (0)