Skip to content

[Algorithm] 정수 제곱근 판별 #75

Description

@hwangJi-dev

💬 문제

[코딩테스트 연습 - 정수 제곱근 판별](https://school.programmers.co.kr/learn/courses/30/lessons/12934)


💬 Idea

  • sqrt로 만든 n의 제곱근 수가 진짜 n의 제곱근이라면 s + 1의 제곱을 리턴하고, 그렇지 않다면 -1을 리턴한다.

💬 풀이

func solution(_ n:Int64)->Int64{lets=Int(sqrt(Double(n)))return s * s == n ?Int64((s +1)*(s +1)):-1}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions