Skip to content

feat: add lesson11 Java & Ts HW #393

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 1 commit 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,5 +1,6 @@
package com.codedifferently.lesson11;

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

public class Lesson11 {
Expand All @@ -9,14 +10,27 @@ public class Lesson11 {
* https://leetcode.com/problems/concatenation-of-array
*/
public int[] getConcatenation(int[] nums) {
return null;

int[] result = new int[nums.length * 2]; // Create a new array with double the size of nums
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should go above each line of code, not at the end of the line.

for (int i = 0; i < nums.length; i++) {
result[i] = nums[i]; // First half of result array gets the elements from nums
result[i + nums.length] =
nums[i]; // Second half of result array gets the same elements from nums
}
return result;
}

/**
* 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;
List<Integer> result = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
if (words[i].indexOf(x) >= 0) { // Check if character 'x' is present in the word
result.add(i); // Add the index of the word to the result
}
}
return result;
}
}
17 changes: 15 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,26 @@
* https://leetcode.com/problems/concatenation-of-array
*/
export function getConcatenation(nums: number[]): number[] {
return [];
const result: number[] = new Array(nums.length * 2); // Create a new array of double the length of nums
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks wrong, please fix.


for (let i = 0; i < nums.length; i++) {
result[i] = nums[i]; // First half of the result array
result[i + nums.length] = nums[i]; // Second half of the result array
}

return result;
}

/**
* 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].includes(x)) { // Check if character 'x' is present in the word
result.push(i); // Add the index of the word to the result
}
}
return result;
}