Just trying to check if the input is a palindrome. Code keeps evaluating to true, but upon debugging, my answers are false;
Maybe I'm confused with == vs .equals?
class Solution {
public boolean isPalindrome(int x) {
int orig = x;
String result = x + "";
char[] original = result.toCharArray();
String compare = "";
if(orig < 10) {
return true;
}
for(int i = original.length-1; i >= 0; i--) {
compare += original[i];
}
//System.out.println(result); -121
//System.out.println(compare); 121
if(result == compare) {
return true;
} else {
return false;
}
}
}