You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I might be wrong, but your method isPalindromeRecurse can be simplified like this:
public static Wrapper isPalindromeRecursive(Node<Integer> node, int length) {
if (length == 0) {
return new Wrapper(node, true);
} else if (length == 1) {
return new Wrapper(node.next, true);
}
Wrapper result = isPalindromeRecursive(n.next, length - 2);
result.palindrome = result.palindrome && node.data == result.node.data;
result.node = node.next;
return result;
}
The case when length == 2 will be covered by length == 0 if we return current node instead of null.
The return logic is also easier without conditionals.
Correct me, please, if there are flaws in my solution.
The text was updated successfully, but these errors were encountered:
I might be wrong, but your method isPalindromeRecurse can be simplified like this:
The case when
length == 2
will be covered bylength == 0
if we return current node instead of null.The return logic is also easier without conditionals.
Correct me, please, if there are flaws in my solution.
The text was updated successfully, but these errors were encountered: