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..a3775c285 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 { @@ -9,14 +10,29 @@ public class Lesson11 { * https://leetcode.com/problems/concatenation-of-array */ public int[] getConcatenation(int[] nums) { - return null; + int n = nums.length; + int ans[] = new int[2 * n]; + for (int i = 0; i < nums.length; i++) { + ans[i] = nums[i]; + ans[i + n] = nums[i]; + } + return ans; } + // Had help to understand better solutions from Joseph, Kimberlee, Nile, and Angelica, we were on + // Jitsi// + /** * Provide the solution to LeetCode 2942 here: * https://leetcode.com/problems/find-words-containing-character/ */ public List findWordsContaining(String[] words, char x) { - return null; + List indices = new ArrayList<>(); + for (int i = 0; i < words.length; i++) { + if (words[i].contains(String.valueOf(x))) { + indices.add(i); + } + } + return indices; } } diff --git a/lesson_11/arrays_ts/src/lesson11.ts b/lesson_11/arrays_ts/src/lesson11.ts index 54af1ba03..ad31b15a2 100644 --- a/lesson_11/arrays_ts/src/lesson11.ts +++ b/lesson_11/arrays_ts/src/lesson11.ts @@ -3,7 +3,13 @@ * https://leetcode.com/problems/concatenation-of-array */ export function getConcatenation(nums: number[]): number[] { - return []; + const n = nums.length; + const ans = new Array(2 * n); + for (let i = 0; i < n; i++) { + ans[i] = nums[i]; + ans[i + n] = nums[i]; + } + return ans; } /** @@ -11,5 +17,11 @@ export function getConcatenation(nums: number[]): number[] { * https://leetcode.com/problems/find-words-containing-character/ */ export function findWordsContaining(words: string[], x: string): number[] { - return []; + const indices: number[] = []; + for (let i = 0; i < words.length; i++) { + if (words[i].includes(x)) { + indices.push(i); + } + } + return indices; }