@@ -10,58 +10,32 @@ public class Lesson11 {
1010 * https://leetcode.com/problems/concatenation-of-array
1111 */
1212 public static int [] getConcatenation (int [] nums ) {
13-
14- int n = nums .length ; // Creates a variable named n that is the length of nums
15- int [] ans = new int [2 * n ]; // Creates a new array that is double the size of n.
13+ // Creates a variable named n that is the length of nums
14+ int n = nums .length ;
15+ // Creates a new array that is double the size of n.
16+ int [] ans = new int [2 * n ];
1617
1718 for (int i = 0 ; i < n ; ++i ) {
18- ans [i ] = nums [i ]; // Gets the first half of the int array
19- ans [i + n ] = nums [i ]; // Gets the second half of the int array
19+ // Gets the first half of the int array
20+ ans [i ] = nums [i ];
21+ // Gets the second half of the int array
22+ ans [i + n ] = nums [i ];
2023 }
2124 return ans ;
2225 }
2326
24- public static void main (String [] args ) {
25-
26- // Creates an instance of the solution class
27- // We need this because getConcatenation() is a method that is non-static meaning we need and
28- // object of Solution to use it.
29- // This would be unneeded if getConcatenation() was static
30-
31- int [] nums = {1 , 2 , 3 , 4 }; // Array of nums based on Test input
32- int [] result =
33- getConcatenation (nums ); // calls the getConcatenation method giving it the array of nums.
34-
35- // Prints result out.
36-
37- // You need to loop out the result because we want to display the contents of an array which
38- // means we need to call each instance in it. This is easily done by using the for else loop to
39- // run until it is returned false.
40- for (int num : result ) {
41- System .out .print (num + " " );
42- }
43-
44- String [] words = {
45- "leet" , "code" , "hello" , "world"
46- }; // Creates an Array named words that contains a series of strings.[]
47-
48- char x = 'e' ; // Calls for a specific char
49- System .out .println (findWordsContaining (words , x )); // Prints out findWordsContaining method
50- }
51-
52- /**
53- * Provide the solution to LeetCode 2942 here:
54- * https://leetcode.com/problems/find-words-containing-character/
55- */
5627 public static List <Integer > findWordsContaining (String [] words , char x ) {
57- ArrayList <Integer > elListo = new ArrayList <>(); // Create an arraylist named ElListo
28+ // Create an arraylist named arrList
29+ ArrayList <Integer > arrList = new ArrayList <>();
5830
5931 // Runs a loop that will iterate through each character in the word.
6032 for (int i = 0 ; i < words .length ; i ++) {
61- if (words [i ].indexOf (x ) != -1 ) { // will check to see if 'x' exists inside of the word
62- elListo .add (i ); // Stores the index if it is true that it has that character
33+ // will check to see if 'x' exists inside of the word
34+ if (words [i ].indexOf (x ) != -1 ) {
35+ // Stores the index if it is true that it has that character
36+ arrList .add (i );
6337 }
6438 }
65- return elListo ; // Will return elListo ArrayList to main
39+ return arrList ;
6640 }
6741}
0 commit comments