Type of Triangle📐🔍: Simple if-else ✨|| 0ms⏰ ||Beats 100%✅ || JAVA ☕️
\n# Intuition\nYou\'re checking the type of triangle based on its side lengths, following these rules:\n\n- If any side length is greater than or equal to the s
![Screenshot 2024-06-23 192115.png](https://assets.leetcode.com/users/images/cc0b01c6-db19-4f2d-8b18-41c620006af1_1719151803.590607.png)\n# Intuition\nYou\'re checking the type of triangle based on its side lengths, following these rules:\n\n- If any side length is greater than or equal to the sum of the other two sides, it\'s not a valid triangle ("none").\n- If all three sides are equal, it\'s an "Equilateral triangle".\n- If exactly two sides are equal, it\'s an "Isosceles triangle".\n- If all sides are different, it\'s a "Scalene triangle".\n\n# Approach\n1. **Input Handling:** You are given nums contains exactly three integers representing the side lengths of a triangle (Check Constraints).\n2. **Triangle Validity Check:** You first check if the given sides can form a triangle using the triangle inequality theorem.\n3. **Triangle Type Determination:** Based on the side lengths:\n- If all sides are equal, return "equilateral".\n- If exactly two sides are equal, return "isosceles".\n- Otherwise, return "scalene".\n\n# Complexity\n- **Time complexity:**\nThe time complexity is **O(1)** since the operations involve a fixed number of comparisons (specifically, 3 comparisons and potentially a few arithmetic operations for checking triangle inequality).\n\n- **Space complexity:**\nThe space complexity is also **O(1)** because you are using a fixed amount of extra space regardless of the input size.\n\n\n# Code\n```\nclass Solution {\n    public String triangleType(int[] nums) {\n        int a = nums[0];\n        int b = nums[1];\n        int c = nums[2];\n\n        if (a+b <= c || b+c <= a || a+c <= b)\n            return "none";\n\n        else if (a == b && b == c)\n            return "equilateral";\n\n        else if (a == b || b == c || a == c)\n            return "isosceles";\n\n        else\n            return "scalene";\n    }\n}\n```\n---\n\n
['Java']