문제 출처:https://leetcode.com/problems/valid-perfect-square/

해당 문제는 이전에 풀었던 문제와 비슷하게 적용가능합니다.
https://coding-leaf.tistory.com/117
Leetcode 문제 69번 Sqrt(x)
문제 출처:https://leetcode.com/problems/sqrtx/ Sqrt(x) - 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 i..
coding-leaf.tistory.com
코드는 다음과 같습니다:
class Solution {
public:
bool isPerfectSquare(int num) {
int a = sqrt(num) ;
return (a*a == num) ? true : false ;
}
int sqrt(int x) {
//Babylonian method
double n = 10.0;
for(int i = 0; i < 100; i++)
n = (n + (x / n)) / 2;
return n;
}
};

해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/LeetCode/P367_Valid_Perfect_Square.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.
문제 출처:https://leetcode.com/problems/valid-perfect-square/

해당 문제는 이전에 풀었던 문제와 비슷하게 적용가능합니다.
https://coding-leaf.tistory.com/117
Leetcode 문제 69번 Sqrt(x)
문제 출처:https://leetcode.com/problems/sqrtx/ Sqrt(x) - 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 i..
coding-leaf.tistory.com
코드는 다음과 같습니다:
class Solution {
public:
bool isPerfectSquare(int num) {
int a = sqrt(num) ;
return (a*a == num) ? true : false ;
}
int sqrt(int x) {
//Babylonian method
double n = 10.0;
for(int i = 0; i < 100; i++)
n = (n + (x / n)) / 2;
return n;
}
};

해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/LeetCode/P367_Valid_Perfect_Square.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.