File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11 Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson11 ;
2
2
3
+ import java .util .ArrayList ;
3
4
import java .util .List ;
4
5
5
6
public class Lesson11 {
@@ -9,14 +10,35 @@ public class Lesson11 {
9
10
* https://leetcode.com/problems/concatenation-of-array
10
11
*/
11
12
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 ;
13
25
}
14
26
15
27
/**
16
28
* Provide the solution to LeetCode 2942 here:
17
29
* https://leetcode.com/problems/find-words-containing-character/
18
30
*/
19
31
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 ;
21
43
}
22
44
}
You can’t perform that action at this time.
0 commit comments