|
1 | 1 | package com.codedifferently.lesson11;
|
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
3 | 4 | import java.util.List;
|
4 | 5 |
|
5 | 6 | public class Lesson11 {
|
6 |
| - |
| 7 | + |
7 | 8 | /**
|
8 |
| - * Provide the solution to LeetCode 1929 here: |
| 9 | + * Implementation of the solution to LeetCode 1929 below: |
9 | 10 | * https://leetcode.com/problems/concatenation-of-array
|
10 | 11 | */
|
11 |
| - public int[] getConcatenation(int[] nums) { |
12 |
| - return null; |
| 12 | + public static int[] getConcatenation(int[] nums) { |
| 13 | + int lenOriginalArray = nums.length; |
| 14 | + int[] concatenatedArrays = new int[lenOriginalArray * 2]; |
| 15 | + |
| 16 | + for(int i= 0; i < lenOriginalArray; i++){ |
| 17 | + concatenatedArrays[i] = nums[i]; |
| 18 | + } |
| 19 | + int nextIndex = lenOriginalArray; |
| 20 | + for(int i= 0; i < lenOriginalArray; i++){ |
| 21 | + concatenatedArrays[nextIndex+i] = nums[i]; |
| 22 | + } |
| 23 | + return concatenatedArrays; |
13 | 24 | }
|
14 | 25 |
|
15 | 26 | /**
|
16 |
| - * Provide the solution to LeetCode 2942 here: |
| 27 | + * Implementation of the solution to LeetCode 2942 below: |
17 | 28 | * https://leetcode.com/problems/find-words-containing-character/
|
18 | 29 | */
|
19 | 30 | public List<Integer> findWordsContaining(String[] words, char x) {
|
20 |
| - return null; |
| 31 | + var indexList = new ArrayList<Integer>(); |
| 32 | + int index = -1; |
| 33 | + for(String word : words){ |
| 34 | + index = index + 1; |
| 35 | + var charactersOfWord = new ArrayList<Character>(); |
| 36 | + char charactersOfCurrentWord[] = word.toCharArray(); |
| 37 | + for(Character xter : charactersOfCurrentWord){ |
| 38 | + charactersOfWord.add(xter); |
| 39 | + } |
| 40 | + if (charactersOfWord.contains(x)){ |
| 41 | + indexList.add(index); |
| 42 | + } |
| 43 | + } |
| 44 | + return indexList; |
21 | 45 | }
|
22 | 46 | }
|
0 commit comments