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,40 @@ 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
+ int n = nums .length ; // Puts length of nums case into n.
14
+ int [] ans = new int [2 * n ]; // Declares ans as an array with 6 values.
15
+
16
+ // Puts whatever is placed on the index number in each num[i] position and copies it to the
17
+ // ans[i] position > depending on what [i] is at the time.
18
+ for (int i = 0 ; i < n ; i ++) {
19
+ ans [i ] = nums [i ];
20
+ }
21
+
22
+ // Same thing as the last one, but with the starting position being on whatever index n is on.
23
+ // In this case, it's starting at index 3, aka, position 4. This is where the concatenation part happens.
24
+ for (int i = 0 ; i < n ; i ++) {
25
+ ans [i + n ] = nums [i ];
26
+ }
27
+ // Side note...I'm not sure if this happens after the first 3 numbers have been added, during
28
+ // each loop, or after.
29
+
30
+ return ans ;
13
31
}
14
32
15
33
/**
16
34
* Provide the solution to LeetCode 2942 here:
17
35
* https://leetcode.com/problems/find-words-containing-character/
18
36
*/
19
37
public List <Integer > findWordsContaining (String [] words , char x ) {
20
- return null ;
38
+ List <Integer > result = new ArrayList <>();
39
+
40
+ // Iterating through the array.
41
+ for (int i = 0 ; i < words .length ; i ++) {
42
+ if (words [i ].indexOf (x ) != -1 ) { // If a particular index contains x, and it does not strictly equal -1 (aka, an index that doesn't exist)...
43
+ result .add (i ); // Then append the index at the end of the list.
44
+ }
45
+ }
46
+
47
+ return result ; // Return the index of x in an array.
21
48
}
22
49
}
0 commit comments