Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Palindrome Number #32

Closed
Tracked by #100
fkdl0048 opened this issue Sep 27, 2024 · 0 comments
Closed
Tracked by #100

Palindrome Number #32

fkdl0048 opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Sep 27, 2024

class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0)
            return false;
        
        int origin = x;
        long revers = 0;

        while (x > 0){
            revers = revers * 10 + (x % 10);
            x = x / 10;
        }

        return (revers == origin);
    }
};

두 가지 방법으로 정수 그대로 뒤집고 비교하는 방법과 문자열로 변환 후 비교하는 방법이 있음, 펠린드롭 수 특징 상 주어진 정수에서 음수인 경우만 제외하면 추가적인 조치가 필요 없음 (문자열로 주어질 때는 필요) 따라서 정수가 더 효율적임

앞서 풀이한 주어진 숫자 뒤집기 연산을 통해 비교함

 return (revers == origin);

결과값 자체가 참 거짓으로 나오기에 반환 연산 생각하기

뒤집을 때, int_MAX값 뚫는거 생각해서 long으로 설정하기

@fkdl0048 fkdl0048 mentioned this issue Sep 27, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Sep 27, 2024
@fkdl0048 fkdl0048 added this to Todo Sep 27, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Sep 27, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Sep 27, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Sep 27, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Sep 27, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
47 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant