Given an integer x
, return true
if x
is palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
121
is a palindrome while 123
is not.Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
-231 <= x <= 231 - 1
정수 x
가 주어지면 x
가 펠린드롬 수이면 true
를 반환합니다.
펠린드롬 수는 정방향과 역방향이 같은 수 입니다.
예를 들어, 121
은 펠린드롬 수이지만 123
은 그렇지 않습니다.
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
num = x.toString();
for(var i = 0; i < num.length; i++) {
if(num[i] != num[num.length - 1 - i])
return false;
}
return true;
};
한번에 성공!
.toString()
: 문자열로 변환
-> 이런건 자바랑 비슷하구나~~ 생각했다 (자바보다 간단한듯)