Skip to content

Commit 42790fc

Browse files
author
“A1-4U2T1NN”
committed
fix: changed .indexOf back to .contains;
1 parent e14064d commit 42790fc

File tree

1 file changed

+8
-7
lines changed
  • lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11

1 file changed

+8
-7
lines changed

lesson_11/arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ public int[] getConcatenation(int[] nums) {
2424
* https://leetcode.com/problems/find-words-containing-character/
2525
*/
2626
public List<Integer> findWordsContaining(String[] words, char x) {
27-
List<Integer> arrayOfIndices = new ArrayList<>(); // Use a List to dynamically store indices
2827

29-
for (int i = 0; i < words.length; i++) {
30-
if (words[i].indexOf(x) != -1) { // Check if the character is present in the word
31-
arrayOfIndices.add(i); // Add the index to the list
32-
}
28+
List<Integer> arrayOfIndices = new ArrayList<>(); // Use a List to dynamically store indices
29+
30+
for (int i = 0; i < words.length; i++) {
31+
if (words[i].contains(x)){ // Check if the character is present in the word
32+
arrayOfIndices.add(i); // Add the index to the list
3333
}
34-
return arrayOfIndices;
34+
}
35+
return arrayOfIndices; // Return list
3536
}
36-
}
37+

0 commit comments

Comments
 (0)