알고리즘, 자료구조/Codewars

[알고리즘] 삼각형인가요? (codewars)

soohkang 2021. 4. 3. 21:05
728x90

 

function isTriangle(a,b,c)
{
	let answer=true, max;
	let total_sum = a+b+c;
	if(a>b) max = a;
	else max = b;
	if(c > max) max = c;

	if(max >= (total_sum-max)) answer = false;

	return answer;
}

 

세 수가 주어졌을 때 가장 큰 수가 나머지 2개의 수를 합한 것보다 크거나 같으면 삼각형을 이룰 수 없다는 점을 알면 코드를 작성할 수 있다.

 

 

출처 : www.codewars.com/kata/56606694ec01347ce800001b/train/javascript

 

Codewars: Achieve mastery through challenge

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com