[LeetCode] Palindrome Number (JS)

nRecode·2021년 3월 11일
0

Algorithm

목록 보기
43/48

문제

Given an integer x, return true if x is palindrome integer.

An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

입출력 예
Input: x = 121
Output: true

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.

접근

간단한 문제입니다.
입력 x를 reverse한 값이 x와 일치하는지 확인 작업만 하면 통과합니다.

풀이

var isPalindrome = function(x) {
    x = x.toString();
    let y = x.split('').reverse().join('');
    
    return x === y;
    
};
profile
안정성, 확장성 있는 서버를 구축하고 가꾸는 개발자를 목표로 공부하고 있습니다. 🤔🤔🤔🤔 부족하기에 맞지 않는 내용이 있을 수 있습니다. 가감없이 피드백 해주시면 정말 감사하겠습니다..🙏

0개의 댓글