Skip to content

Commit 6c5e88b

Browse files
committed
Refactor: Removed Main method and test cases. Also made comments cleaning
1 parent 832eea3 commit 6c5e88b

File tree

2 files changed

+20
-63
lines changed

2 files changed

+20
-63
lines changed

lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
*/
66
export function getConcatenation(nums: number[]): number[] {
77
const n = nums.length; //Creates a variable named n that is the length of nums
8-
const ans: number[] = new Array(2 * n); //Creates a new array that is double the size of n
9-
8+
const ans = new Array(2 * n); //Creates a new array that is double the size of n
109

1110
for(let i = 0; i < n; ++i) {
1211
ans[i] = nums[i];
1312
ans[i + n] = nums[i];
14-
15-
1613
}
1714
return ans;
1815
}
@@ -23,28 +20,14 @@ export function getConcatenation(nums: number[]): number[] {
2320
* https://leetcode.com/problems/find-words-containing-character/
2421
*/
2522
export function findWordsContaining(words: string[], x: string): number[] {
26-
const elListo: number[] = [] //creates a new array named elListo
27-
23+
//creates a new array list names arrList
24+
const arrList: number[] = []
2825

2926
//Runs a loop that will iterate through each character in the String.
3027
for (let i = 0; i < words.length; ++i) {
3128
if (words[i].includes(x)) { //Checks to see if the word inclues the char 'x'
32-
elListo.push(i); //Pushes the index of i if it is true that the word contains that character
33-
29+
arrList.push(i); //Pushes the index of i if it is true that the word contains that character
3430
}
35-
} return elListo; //Will return the Array elListo
31+
} return arrList; //Will return the Array elListo
3632
}
3733

38-
39-
//Test Cases
40-
41-
42-
const nums: number[] = [1, 2 , 3, 4]; //Array of numbers based on test case
43-
const result: number[] = getConcatenation(nums);
44-
console.log(result.join(' '))//Prints the test result out for the fet concatentaition method
45-
46-
47-
const words: string[] = ['leet', 'code', 'hello', 'world']; //Array of strings based on test case
48-
const x = 'e'; //Calls for a specific char
49-
console.log(findWordsContaining(words, x));
50-

0 commit comments

Comments
 (0)