diff --git a/lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java b/lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java index 248938a96..47fdf2768 100644 --- a/lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java +++ b/lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java @@ -1,5 +1,6 @@ package com.codedifferently.lesson11; +import java.util.ArrayList; import java.util.List; public class Lesson11 { @@ -8,15 +9,33 @@ public class Lesson11 { * Provide the solution to LeetCode 1929 here: * https://leetcode.com/problems/concatenation-of-array */ - public int[] getConcatenation(int[] nums) { - return null; + public static int[] getConcatenation(int[] nums) { + // Creates a variable named n that is the length of nums + int n = nums.length; + // Creates a new array that is double the size of n. + int[] ans = new int[2 * n]; + + for (int i = 0; i < n; ++i) { + // Gets the first half of the int array + ans[i] = nums[i]; + // Gets the second half of the int array + ans[i + n] = nums[i]; + } + return ans; } - /** - * Provide the solution to LeetCode 2942 here: - * https://leetcode.com/problems/find-words-containing-character/ - */ - public List findWordsContaining(String[] words, char x) { - return null; + public static List findWordsContaining(String[] words, char x) { + // Create an arraylist named arrList + ArrayList arrList = new ArrayList<>(); + + // Runs a loop that will iterate through each character in the word. + for (int i = 0; i < words.length; i++) { + // will check to see if 'x' exists inside of the word + if (words[i].indexOf(x) != -1) { + // Stores the index if it is true that it has that character + arrList.add(i); + } + } + return arrList; } } diff --git a/lesson_11/arrays_ts/src/lesson11.ts b/lesson_11/arrays_ts/src/lesson11.ts index 54af1ba03..8c227f6af 100644 --- a/lesson_11/arrays_ts/src/lesson11.ts +++ b/lesson_11/arrays_ts/src/lesson11.ts @@ -1,15 +1,37 @@ + /** - * Provide the solution to LeetCode 1929 here: - * https://leetcode.com/problems/concatenation-of-array - */ +* Provide the solution to LeetCode 1929 here: +* https://leetcode.com/problems/concatenation-of-array +*/ export function getConcatenation(nums: number[]): number[] { - return []; + //Creates a variable named n that is the length of nums + const n = nums.length; + //Creates a new array that is double the size of n + const ans = new Array(2 * n); + + for (let i = 0; i < n; ++i) { + ans[i] = nums[i]; + ans[i + n] = nums[i]; + } + return ans; } /** - * Provide the solution to LeetCode 2942 here: - * https://leetcode.com/problems/find-words-containing-character/ - */ +* Provide the solution to LeetCode 2942 here: +* https://leetcode.com/problems/find-words-containing-character/ +*/ export function findWordsContaining(words: string[], x: string): number[] { - return []; + //creates a new array list names arrList + const arrList: number[] = []; + + //Runs a loop that will iterate through each character in the String. + for (let i = 0; i < words.length; ++i) { + //Checks to see if the word inclues the char 'x' + if (words[i].includes(x)) { + //Pushes the index of i if it is true that the word contains that character + arrList.push(i); + } + //Will return the Array list arrList + } return arrList; } +