Skip to content

Commit b26f7a1

Browse files
committed
feat: finished Java and ts methods
1 parent 04da675 commit b26f7a1

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
Lines changed: 18 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,29 @@ public class Lesson11 {
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
/**
1625
* Provide the solution to LeetCode 2942 here:
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+
for (int i = 0; i < words.length; i++) {
32+
if (words[i].contains(x+"")) {
33+
result.add(i);
34+
}
35+
}
36+
return result;
2137
}
2238
}

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
* https://leetcode.com/problems/concatenation-of-array
44
*/
55
export function getConcatenation(nums: number[]): number[] {
6-
return [];
6+
let combinedArr = nums.concat(nums);
7+
return combinedArr;
78
}
89

910
/**
1011
* Provide the solution to LeetCode 2942 here:
1112
* https://leetcode.com/problems/find-words-containing-character/
1213
*/
1314
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
15+
let result: number[] = [];
16+
17+
for (let i = 0; i < words.length; i++) {
18+
if (words[i].includes(x)) {
19+
result.push(i);
20+
}
21+
}
22+
23+
return result;
1524
}

0 commit comments

Comments
 (0)