─━ IT ━─

[릿코드, Leetcode] [JAVA] Palindrome Number

DKel 2021. 4. 4. 08:00
반응형
 

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

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;
    }
}

제출한 소스코드

 

lemondkel - Overview

4-Year Web programmer. lemondkel has 41 repositories available. Follow their code on GitHub.

github.com

 

 

팰린드롬 문제!

반응형