Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
- 회문 숫자인지 아닌지 검사하여 boolean 반환하기
- Palindrome(회문)은 문자열을 거꾸로 해도 원래의 문자열과 같은 문자열인 특징을 가지고 있는 문자열을 가리키는 말 (예시 : 토마토, 양배추배양)
example
Example 1:
Input: 121
Output: trueExample 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.Example 3:
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
const reverseX = String(x).split('').reverse().join('');
if(String(x) === reverseX) {
return true;
}
return false;
};
var isPalindrome = function(x) {
const stringWrap = String(x);
let startIndex = 0;
let endIndex = stringWrap.length-1;
while(startIndex < endIndex) {
if(stringWrap[startIndex] == stringWrap[endIndex]) {
startIndex++;
endIndex--;
} else {
return false;
}
}
return true;
};