From c585422d643252924194811d6204f773a35ca5e0 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 19 May 2025 16:28:17 -0600 Subject: 3024. type of triangle --- type_of_triangle.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 type_of_triangle.py (limited to 'type_of_triangle.py') diff --git a/type_of_triangle.py b/type_of_triangle.py new file mode 100644 index 0000000..17dd7dd --- /dev/null +++ b/type_of_triangle.py @@ -0,0 +1,29 @@ +# 3024. Type of Triangle + +""" +you are given a 0-indexed integer array 'nums' of size 3 which can form the +sides of a triangle. return a string representing the type of triangle that +can be formed, or none if it cannot form a triangle. +""" + + +class Solution(object): + def triangleType(self, nums): + """ + :type nums: List[int] + :rtype: str + """ + nums.sort() + if nums[2] >= nums[0] + nums[1]: + return "none" + if nums[0] == nums[2]: + return "equilateral" + if nums[0] == nums[1] or nums[1] == nums[2]: + return "isosceles" + return "scalene" + + +if __name__ == "__main__": + obj = Solution() + print(obj.triangleType(nums=[3, 3, 3])) + print(obj.triangleType(nums=[3, 4, 5])) -- cgit v1.2.3