Show problems as
Classic problem #3024EasyArrayMathSortingPolygons

Type of Triangle

Real-world version: Naming the Shape of Three Rods
Tracked in this browser only
Read Type of Triangle on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Three rod lengths are given as rods.

Return the name of the triangle they form:

  • "none" when they cannot form a triangle at all, which happens exactly when some two of them added together do not exceed the third;
  • "equilateral" when all three are the same length;
  • "isosceles" when exactly two are the same length;
  • "scalene" when no two are the same length.

Examples

Example 1

Input
rods = [2, 2, 3]
Output
"isosceles"

Two and two added together exceed three, so a triangle is possible, and exactly two of the rods are the same length.

Example 2

Input
rods = [1, 1, 5]
Output
"none"

The two short rods add to two, which does not exceed five, so they cannot close into a triangle at all.

Example 3

Input
rods = [6, 7, 8]
Output
"scalene"

Six and seven exceed eight, so a triangle is possible, and no two rods are the same length.

Constraints

  • rods.length == 3
  • 1 <= rods[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def triangle_type(rods: list[int]) -> str:
Java
public String triangleType(int[] rods)