Type of Triangle
Intuition\nThe problem requires determining the type of a triangle based on the lengths of its sides. A triangle can be categorized as:\n- Equilateral: All thre
# Intuition\nThe problem requires determining the type of a triangle based on the lengths of its sides. A triangle can be categorized as:\n- **Equilateral**: All three sides are equal.\n- **Isosceles**: Two sides are equal.\n- **Scalene**: All sides are different.\n- **None**: If the sides don\'t form a valid triangle.\n\nMy first thought is to use the triangle inequality theorem, which ensures that the sum of the lengths of any two sides must be greater than the length of the third side. Sorting the array of side lengths simplifies the logic for checking this condition and for comparing the sides.\n\n# Approach\n1. **Sort the Array**: First, sort the array to easily apply the triangle inequality theorem (`nums[0] + nums[1] > nums[2]`).\n   \n2. **Check Validity**: After sorting, check whether the sides form a valid triangle by verifying that the sum of the two smaller sides is greater than the third side.\n\n3. **Classify the Triangle**: \n   - If all sides are equal, it\'s an **equilateral** triangle.\n   - If two sides are equal, it\'s an **isosceles** triangle.\n   - If all sides are different, it\'s a **scalene** triangle.\n\n4. **Return Result**: If the triangle doesn\'t meet the validity condition, return `"none"`. Otherwise, classify it based on the side lengths.\n\n# Complexity\n- **Time complexity**: \n  - Sorting the array takes (O(log n)) for (n = 3), but this simplifies to constant time, (O(1)), for a fixed-size array of 3 elements.\n  - The triangle classification itself is constant time, so overall complexity is **(O(1))**.\n  \n- **Space complexity**: \n  - Sorting is in-place, so the only space used is constant, (O(1)).\n\n# Code\n```java []\nclass Solution {\n    public String triangleType(int[] nums) {\n        // Sort the array to make the logic clearer\n        Arrays.sort(nums);\n\n        // Check for a valid triangle first (triangle inequality)\n        if (nums[0] + nums[1] <= nums[2]) {\n            return "none";\n        }\n\n        // Check for equilateral\n        if (nums[0] == nums[1] && nums[1] == nums[2]) {\n            return "equilateral";\n        }\n\n        // Check for isosceles\n        if (nums[0] == nums[1] || nums[1] == nums[2] || nums[0] == nums[2]) {\n            return "isosceles";\n        }\n\n        // If it\'s not equilateral or isosceles, it must be scalene\n        return "scalene";\n    }\n}\n```
['Array', 'Math', 'Sorting', 'Java']