Mastering Triangle Classification with C++ || Beats 100% || O(1) || Easy for beginners to understand
IntuitionThe problem requires us to determine the type of triangle that can be formed from three given side lengths. The key conditions to check are:Triangle Va
# Intuition
The problem requires us to determine the type of triangle that can be formed from three given side lengths. The key conditions to check are:

Triangle Validity:

A triangle is only valid if the sum of any two sides is greater than the third side.
This ensures the given lengths satisfy the Triangle Inequality Theorem.

Classifying Triangle Types:

If all three sides are equal → "equilateral".
If only two sides are equal → "isosceles".
If all three sides are different → "scalene".
If the given sides do not form a valid triangle → "none".

<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
Step 1: Check Triangle Validity
A valid triangle must satisfy:

        nums[0]+nums[1]>nums[2]

        nums[1]+nums[2]>nums[0]

        nums[0]+nums[2]>nums[1]

If this condition is not met, return "none" immediately.

Step 2: Sort the Array

Sorting ensures a consistent way to compare the sides.
The smallest side is at nums[0], the middle at nums[1], and the largest at nums[2].

Step 3: Classify the Triangle

Equilateral Triangle:

If all three sides are equal (nums[0] == nums[1] == nums[2]), return "equilateral".

Isosceles Triangle:

If any two sides are equal but not all three, return "isosceles".

Scalene Triangle:

If all three sides are different, return "scalene".

<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(1) 
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    string triangleType(vector<int>& nums) {
        if (nums[0] + nums[1] > nums[2] && nums[1] + nums[2] > nums[0] && nums[0] + nums[2] > nums[1]) {
            sort(nums.begin(),nums.end());
            if(nums[0]!=nums[1] && nums[1]!=nums[2]) return "scalene";
            else if(nums[0] == nums[1] && nums[0] != nums[2] || nums[0] != nums[1] && nums[1] == nums[2] || nums[0] == nums[2] && nums[1] != nums[2]) return "isosceles";
            else return "equilateral";
        }
        else{
            return "none";
        }
        
        return "none";
    }
};
```
['Array', 'Math', 'Sorting', 'C++']