Skip to content

feat : Leet Code implementation for lesson11 less code lines approach by Yemi #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package com.codedifferently.lesson11;

import java.util.ArrayList;
import java.util.List;

public class Lesson11 {

/**
* Provide the solution to LeetCode 1929 here:
* https://leetcode.com/problems/concatenation-of-array
*/
public int[] getConcatenation(int[] nums) {
return null;
int lenOriginalArray = nums.length;
int[] concatenatedArrays = new int[lenOriginalArray * 2];
int pos = 0;

System.arraycopy(nums, pos, concatenatedArrays, pos, lenOriginalArray);
System.arraycopy(nums, pos, concatenatedArrays, lenOriginalArray, lenOriginalArray);
return concatenatedArrays;
}

/**
* Provide the solution to LeetCode 2942 here:
* https://leetcode.com/problems/find-words-containing-character/
*/
public List<Integer> findWordsContaining(String[] words, char x) {
return null;
var indexList = new ArrayList<Integer>(0);
int index = 0;
for (String word : words) {
if (word.indexOf(x) != -1) {
indexList.add(index);
}
index = index + 1;
}
return indexList;
}
}
32 changes: 30 additions & 2 deletions lesson_11/arrays_ts/src/lesson11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,41 @@
* https://leetcode.com/problems/concatenation-of-array
*/
export function getConcatenation(nums: number[]): number[] {
return [];
if (nums.length === 0) {
return [];
}
const lenOriginalArray: number = nums.length;
const concatenatedArrays: number[] = [lenOriginalArray * 2];
for (let i = 0; i < lenOriginalArray; i++) {
concatenatedArrays[i] = nums[i];
}
const nextIndex = lenOriginalArray;
for (let i = 0; i < lenOriginalArray; i++) {
concatenatedArrays[nextIndex + i] = nums[i];
}
return concatenatedArrays;
}

/**
* 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 indexList: number[] = [];
if (words.length === 0){
return [];
}
let index = -1;
for (const word of words) {
index = index + 1;
const charactersOfWord = [];
const charactersOfCurrentWord: string[] = word.split('');
for (const xter of charactersOfCurrentWord) {
charactersOfWord.push(xter);
}
if (charactersOfWord.includes(x)) {
indexList.push(index);
}
}
return indexList;
}