Skip to content

Commit b726523

Browse files
committed
feat: adds brute-force implementation of leetcode 1929 and 2942 for homework11 by Yemi
1 parent 3e8f77b commit b726523

File tree

1 file changed

+30
-6
lines changed
  • lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11

1 file changed

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

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

56
public class Lesson11 {
6-
7+
78
/**
8-
* Provide the solution to LeetCode 1929 here:
9+
* Implementation of the solution to LeetCode 1929 below:
910
* https://leetcode.com/problems/concatenation-of-array
1011
*/
11-
public int[] getConcatenation(int[] nums) {
12-
return null;
12+
public static int[] getConcatenation(int[] nums) {
13+
int lenOriginalArray = nums.length;
14+
int[] concatenatedArrays = new int[lenOriginalArray * 2];
15+
16+
for(int i= 0; i < lenOriginalArray; i++){
17+
concatenatedArrays[i] = nums[i];
18+
}
19+
int nextIndex = lenOriginalArray;
20+
for(int i= 0; i < lenOriginalArray; i++){
21+
concatenatedArrays[nextIndex+i] = nums[i];
22+
}
23+
return concatenatedArrays;
1324
}
1425

1526
/**
16-
* Provide the solution to LeetCode 2942 here:
27+
* Implementation of the solution to LeetCode 2942 below:
1728
* https://leetcode.com/problems/find-words-containing-character/
1829
*/
1930
public List<Integer> findWordsContaining(String[] words, char x) {
20-
return null;
31+
var indexList = new ArrayList<Integer>();
32+
int index = -1;
33+
for(String word : words){
34+
index = index + 1;
35+
var charactersOfWord = new ArrayList<Character>();
36+
char charactersOfCurrentWord[] = word.toCharArray();
37+
for(Character xter : charactersOfCurrentWord){
38+
charactersOfWord.add(xter);
39+
}
40+
if (charactersOfWord.contains(x)){
41+
indexList.add(index);
42+
}
43+
}
44+
return indexList;
2145
}
2246
}

0 commit comments

Comments
 (0)