0. 문제
https://leetcode.com/problems/palindrome-number/
Palindrome Number - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
정수가 주어지면 회문일 경우 true 회문이 아닐 경우 false를 반환한다.
#1
Input: x = 121
Output: true
#2
Input: x = -121
Output: false
#3
Input: x = 10
Output: false
1.언어
자바스크립트(JavaScript)
2. 문제 풀이
isPalindrome = function(x) {
return String(x).split('').reverse().join('') == x
};
Runtime: 193 ms, faster than 86.66% of JavaScript online submissions for Palindrome Number.
Memory Usage: 51.3 MB, less than 42.65% of JavaScript online submissions for Palindrome
입력값 x(121)를 문자열('121') -> 배열(['1','2','1']) -> 배열 뒤집기(['1','2','1']) -> 배열 합쳐서 문자열로 변환( '121') -> 비교 값 반환
한번에 통과!
'LeetCode > 코딩 테스트 스터디 1주차' 카테고리의 다른 글
[LeetCode] 3. Longest Substring Without Repeating Characters 풀이 (0) | 2022.07.10 |
---|---|
[LeetCode] 2. Add Two Numbers 풀이 (0) | 2022.07.10 |
[LeetCode] 14. Longest Common Prefix 풀이 (0) | 2022.07.10 |
[LeetCode] 13. Roman to Integer 풀이 (0) | 2022.07.10 |
[LeetCode] 1. Two Sum 풀이 (0) | 2022.07.10 |