Skip to content
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
Expand Up @@ -3,7 +3,7 @@
* <p>
* Time Complexity: O(n) [or appropriate complexity]
* Space Complexity: O(n)
* * @author Reshma Kakkirala
* @author Reshma Kakkirala
*/
package com.thealgorithms.conversions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public <T extends Comparable<T>> int find(T[] array, T key) {

int i = 0;
// Search without bound checking since sentinel guarantees we'll find the key
while (array[i].compareTo(key) != 0) {
// Null check for array element to prevent NPE when array contains null elements
while (array[i] != null && array[i].compareTo(key) != 0) {
i++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static String reverse3(String string) {
/**
* Reverses the given string using a stack.
* This method uses a stack to reverse the characters of the string.
* * @param str The input string to be reversed.
* @param str The input string to be reversed.
* @return The reversed string.
*/
public static String reverseStringUsingStack(String str) {
Expand Down
Loading