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..6e6326f57 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,22 +1,41 @@ package com.codedifferently.lesson11; +import java.util.ArrayList; import java.util.List; public class Lesson11 { /** - * Provide the solution to LeetCode 1929 here: + * Solution to LeetCode problem: Concatenation of Array * https://leetcode.com/problems/concatenation-of-array */ public int[] getConcatenation(int[] nums) { - return null; + int size = nums.length; + + int[] result = new int[size * 2]; + + for (int i = 0; i < size * 2; i++) { + result[i] = nums[i % size]; + } + + return result; } /** - * Provide the solution to LeetCode 2942 here: + * Solution to LeetCode problem: Find Words Containing Character * https://leetcode.com/problems/find-words-containing-character/ */ public List findWordsContaining(String[] words, char x) { - return null; + List result = new ArrayList<>(); + + String searchChar = String.valueOf(x); + + for (int i = 0; i < words.length; i++) { + if (words[i].contains(searchChar)) { + result.add(i); + } + } + + return result; } } diff --git a/lesson_11/arrays_ts/src/lesson11.ts b/lesson_11/arrays_ts/src/lesson11.ts index 54af1ba03..c77def735 100644 --- a/lesson_11/arrays_ts/src/lesson11.ts +++ b/lesson_11/arrays_ts/src/lesson11.ts @@ -3,7 +3,7 @@ * https://leetcode.com/problems/concatenation-of-array */ export function getConcatenation(nums: number[]): number[] { - return []; + return [...nums, ... nums]; } /** @@ -11,5 +11,7 @@ export function getConcatenation(nums: number[]): number[] { * https://leetcode.com/problems/find-words-containing-character/ */ export function findWordsContaining(words: string[], x: string): number[] { - return []; + return words + .map((word, index) => (word.includes(x) ? index : -1)) + .filter(index => index !== -1); }