반응형
Leetcode - Palindrome Number
설명
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.
Example:
Input: x = 121
Output: true
소스코드
class Solution {
public boolean isPalindrome(int x) {
boolean answer = true;
char[] items = String.valueOf(x).toCharArray();
for (int i=0; i<items.length/2; i++) {
if (items[i] != items[items.length-i-1]) return false;
}
return answer;
}
}
팰린드롬 문제!
반응형