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..b1ec096cc 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,7 +10,14 @@ public class Lesson11 { * https://leetcode.com/problems/concatenation-of-array */ public int[] getConcatenation(int[] nums) { - return null; + + int answer[] = new int[2 * nums.length]; + for (int i = 0; i < nums.length; i++) { + answer[i] = nums[i]; + answer[i + nums.length] = nums[i]; + } + + return answer; } /** @@ -17,6 +25,16 @@ public int[] getConcatenation(int[] nums) { * https://leetcode.com/problems/find-words-containing-character/ */ public List findWordsContaining(String[] words, char x) { - return null; + + List result = new ArrayList<>(); + + for (int i = 0; i < words.length; i++) { + + if (words[i].indexOf(x) != -1) { + 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..c94555986 100644 --- a/lesson_11/arrays_ts/src/lesson11.ts +++ b/lesson_11/arrays_ts/src/lesson11.ts @@ -3,13 +3,27 @@ * https://leetcode.com/problems/concatenation-of-array */ export function getConcatenation(nums: number[]): number[] { - return []; + const answer: number[] = new Array(2 * nums.length); + for (let i = 0; i < nums.length; i++) { + answer[i] = nums[i]; + answer[i + nums.length] = nums[i]; + } + return answer; } + /** * Provide the solution to LeetCode 2942 here: * https://leetcode.com/problems/find-words-containing-character/ */ export function findWordsContaining(words: string[], x: string): number[] { - return []; + + const result: number[] = []; + for (let i = 0; i < words.length; i++) { + if (words[i].indexOf(x) !== -1) { + result.push(i); + } + } + return result; } +