From 522243bfc35cf782b6386910dc982baff9a47399 Mon Sep 17 00:00:00 2001 From: jbey251 Date: Mon, 31 Mar 2025 15:47:34 +0000 Subject: [PATCH 1/2] FEATURE: Create concatenation function & indexing function. --- .../codedifferently/lesson11/Lesson11.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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..bff70fdad 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,24 @@ public class Lesson11 { * https://leetcode.com/problems/concatenation-of-array */ public int[] getConcatenation(int[] nums) { - return null; + int n = nums.length; // Puts length of nums case into n. + int[] ans = new int[2 * n]; // Declares ans as an array with 6 values. + + // Puts whatever is placed on the index number in each num[i] position and copies it to the + // ans[i] position > depending on what [i] is at the time. + for (int i = 0; i < n; i++) { + ans[i] = nums[i]; + } + + // Same thing as the last one, but with the starting position being on whatever index n is on. + // In this case, it's starting at index 3, aka, position 4. This is where the concatenation part happens. + for (int i = 0; i < n; i++) { + ans[i + n] = nums[i]; + } + // Side note...I'm not sure if this happens after the first 3 numbers have been added, during + // each loop, or after. + + return ans; } /** @@ -17,6 +35,15 @@ 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<>(); + + // Iterating through the array. + for (int i = 0; i < words.length; i++) { + if (words[i].indexOf(x) != -1) { // If a particular index contains x, and it does not strictly equal -1 (aka, an index that doesn't exist)... + result.add(i); // Then append the index at the end of the list. + } + } + + return result; // Return the index of x in an array. } } From 05a6bd727b7d702f08d790ce0b30febcf61fc72b Mon Sep 17 00:00:00 2001 From: jbey251 Date: Tue, 1 Apr 2025 13:23:56 +0000 Subject: [PATCH 2/2] FEATURE: Concatenate & word indexes. --- .../main/java/com/codedifferently/lesson11/Lesson11.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 bff70fdad..447ec4fa3 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 @@ -20,7 +20,8 @@ public int[] getConcatenation(int[] nums) { } // Same thing as the last one, but with the starting position being on whatever index n is on. - // In this case, it's starting at index 3, aka, position 4. This is where the concatenation part happens. + // In this case, it's starting at index 3, aka, position 4. This is where the concatenation part + // happens. for (int i = 0; i < n; i++) { ans[i + n] = nums[i]; } @@ -38,8 +39,10 @@ public List findWordsContaining(String[] words, char x) { List result = new ArrayList<>(); // Iterating through the array. - for (int i = 0; i < words.length; i++) { - if (words[i].indexOf(x) != -1) { // If a particular index contains x, and it does not strictly equal -1 (aka, an index that doesn't exist)... + for (int i = 0; i < words.length; i++) { + if (words[i].indexOf(x) + != -1) { // If a particular index contains x, and it does not strictly equal -1 (aka, an + // index that doesn't exist)... result.add(i); // Then append the index at the end of the list. } }