Algorithm/LeetCode

[LeetCode] Palindrome Number (대칭수)

코딩 테스트 대비 leetcode에서 지인과 함께 1일 1코테를 하려고 한다.

 

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

gist.github.com/devjun63/2f506c247a0e793ff0ff6a974499946b

 

leetcode - Palindrome Number Solve

leetcode - Palindrome Number Solve. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

class Solution {
    public boolean isPalindrome(int x) {
        if(x >= 0)// 0은 포함되어야 함, x > 0 했다가 에러 터져서 변경
        {
            int resultNumber;
            resultNumber = flipNumber(x);
            if(x == resultNumber) return true;
        }
        return false;
    }
    
    public int flipNumber(int original) {
        int temp = 0;
        while(original != 0)
        {
            temp = temp * 10 + original % 10;
            original = original / 10;
        }
        return temp;
    }
}

채점결과:
Runtime: 7 ms, faster than 71.56% of Java online submissions for Palindrome Number.
Memory Usage: 38.1 MB, less than 87.64% of Java online submissions for Palindrome Number.

'Algorithm > LeetCode' 카테고리의 다른 글

[LeetCode] Divisor Game  (0) 2021.03.08
[LeetCode] Fibonacci number (피보나치 수열)  (0) 2021.03.06
[LeetCode] Sort Colors  (0) 2021.03.05
[LeetCode] Make The String Great  (0) 2021.03.04
[LeetCode] Assign Cookies  (3) 2021.03.03