|
| 1 | + |
1 | 2 | /**
|
2 |
| - * Provide the solution to LeetCode 1929 here: |
3 |
| - * https://leetcode.com/problems/concatenation-of-array |
4 |
| - */ |
| 3 | +* Provide the solution to LeetCode 1929 here: |
| 4 | +* https://leetcode.com/problems/concatenation-of-array |
| 5 | +*/ |
5 | 6 | export function getConcatenation(nums: number[]): number[] {
|
6 |
| - return []; |
| 7 | + const n = nums.length; //Creates a variable named n that is the length of nums |
| 8 | + const ans: number[] = new Array(2 * n); //Creates a new array that is double the size of n |
| 9 | + |
| 10 | + |
| 11 | + for(let i = 0; i < n; ++i) { |
| 12 | + ans[i] = nums[i]; |
| 13 | + ans[i + n] = nums[i]; |
| 14 | + |
| 15 | + |
| 16 | + } |
| 17 | + return ans; |
7 | 18 | }
|
8 | 19 |
|
| 20 | + |
9 | 21 | /**
|
10 |
| - * Provide the solution to LeetCode 2942 here: |
11 |
| - * https://leetcode.com/problems/find-words-containing-character/ |
12 |
| - */ |
| 22 | +* Provide the solution to LeetCode 2942 here: |
| 23 | +* https://leetcode.com/problems/find-words-containing-character/ |
| 24 | +*/ |
13 | 25 | export function findWordsContaining(words: string[], x: string): number[] {
|
14 |
| - return []; |
| 26 | + const elListo: number[] = [] //creates a new array named elListo |
| 27 | + |
| 28 | + |
| 29 | + //Runs a loop that will iterate through each character in the String. |
| 30 | + for (let i = 0; i < words.length; ++i) { |
| 31 | + if (words[i].includes(x)) { //Checks to see if the word inclues the char 'x' |
| 32 | + elListo.push(i); //Pushes the index of i if it is true that the word contains that character |
| 33 | + |
| 34 | + } |
| 35 | + } return elListo; //Will return the Array elListo |
15 | 36 | }
|
| 37 | + |
| 38 | + |
| 39 | +//Test Cases |
| 40 | + |
| 41 | + |
| 42 | +const nums: number[] = [1, 2 , 3, 4]; //Array of numbers based on test case |
| 43 | +const result: number[] = getConcatenation(nums); |
| 44 | +console.log(result.join(" "))//Prints the test result out for the fet concatentaition method |
| 45 | + |
| 46 | + |
| 47 | +const words: string[] = ["leet", "code", "hello", "world"]; //Array of strings based on test case |
| 48 | +const x: string = 'e'; //Calls for a specific char |
| 49 | +console.log(findWordsContaining(words, x)); |
| 50 | + |
0 commit comments