Skip to content

Commit f3c896b

Browse files
feat:adds Karens lesson11 leetcode solutions
1 parent ac458a6 commit f3c896b

File tree

1 file changed

+24
-2
lines changed
  • lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11

1 file changed

+24
-2
lines changed
Lines changed: 24 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,35 @@ public class Lesson11 {
910
* https://leetcode.com/problems/concatenation-of-array
1011
*/
1112
public int[] getConcatenation(int[] nums) {
12-
return null;
13+
// used AI to implement this solution
14+
if (nums == null || nums.length == 0) {
15+
return new int[0];
16+
}
17+
int originalLength = nums.length;
18+
int[] result = new int[originalLength * 2];
19+
20+
for (int i = 0; i < originalLength; i++) {
21+
result[i] = nums[i];
22+
result[i + originalLength] = nums[i];
23+
}
24+
return result;
1325
}
1426

1527
/**
1628
* Provide the solution to LeetCode 2942 here:
1729
* https://leetcode.com/problems/find-words-containing-character/
1830
*/
1931
public List<Integer> findWordsContaining(String[] words, char x) {
20-
return null;
32+
// Montell helped me out with with coding implementation
33+
// need to create a string array
34+
List<Integer> search = new ArrayList<>();
35+
// iterate through elements in string array and compare them with the character
36+
for (int i = 0; i < words.length; i++) {
37+
if (words[i].contains(String.valueOf(x))) {
38+
search.add(i);
39+
}
40+
}
41+
// return the index of the element in the string array that contains the character provided
42+
return search;
2143
}
2244
}

0 commit comments

Comments
 (0)