inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 227. 정수의 제곱근 판별

    프로그래머스 (12934)
    Stupefyee's avatar
    Stupefyee
    Apr 28, 2025
    [JAVA 문제 풀이] 227. 정수의 제곱근 판별
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/12934
    notion image
     

    내가 작성한 코드

    class Solution { public long solution(long n) { long answer = 1; while (answer <= Math.sqrt(n)) { if(Math.pow(answer, 2) == n) { answer++; return answer * answer; } answer++; } return -1; } }
     

    다른 사람의 코드

    class Solution { public long solution(long n) { if (Math.pow((int)Math.sqrt(n), 2) == n) { return (long) Math.pow(Math.sqrt(n) + 1, 2); } return -1; } }
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog