숫자 반전 알고리즘

2021. 6. 2. 10:43·Algorithm/JAVA
//핵심
주어진 수의 맨 뒷자리부터 %로 하나씩 가져오고, 자릿수 0을 붙여주면서 기존 수를 / 을 통해 뒷자리부터 삭제 시켜 나간다.

class Solution {
    public boolean isPalindrome(int x) {
        
        if(x < 0) {
            return false;
        }
        
        int originX = x;
        int result = 0;
        
        while(x != 0){
            result = (result * 10) + x%10;
            x /= 10;
        }
        
        if(result == originX){
            return true;
        }
        
        return false;
    }
}

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

Algorithm Study - 003  (0) 2021.06.03
Algorithm Study - 002  (0) 2021.06.02
Algorithm Study - 001  (0) 2021.06.02
'Algorithm/JAVA' 카테고리의 다른 글
  • Algorithm Study - 003
  • Algorithm Study - 002
  • Algorithm Study - 001
seowooJeong
seowooJeong
  • seowooJeong
    개발일기
    seowooJeong
  • 전체
    오늘
    어제
    • 분류 전체보기 (25)
      • FrontEnd (6)
      • BackEnd (6)
      • Project (6)
      • Algorithm (4)
        • JAVA (4)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • React
    • Spring
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    intellij querydsl
    숫자 알고리즘
    jenkinsfile
    숫자 반전
    mybatis list
    QueryDSL 오류
    Spring QueryDsl
    jeknins 파이프라인
    collection 리스트
    build.gradle querydsl
    Java
    resultmap 리스트
    jQuery
    resultmap 중첩
    gitlab ci/cd
    숫자 거꾸로
    spring msa cicd
    querydsl 환경설정
    jenkins gitlab
    jenkinsfile 설정
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
seowooJeong
숫자 반전 알고리즘
상단으로

티스토리툴바