LabHub

블로그

leetcode_9_Palindrome_Number

한국어English日本語

    public static boolean isPalindrome(int x) {
        if(x<0) return false;
        ArrayList<Character> chars = new ArrayList<>();
        while(x>0){
            chars.add((char)(x%10+'0'));
            x = x/10;
        }
        int len_chars = chars.size();
        for(int i=0; i<len_chars/2; i++){
            if(chars.get(i) != chars.get(len_chars-i-1)){
                return false;
            }
        }
        return true;
    }

댓글

아직 댓글이 없습니다.

로그인하면 댓글을 쓸 수 있습니다