✅THE BEST EXPLANATION||Beats 100% Users
---\n# PLEASE UPVOTE IF YOU LIKE IT \u2705\n---\n\n\n---\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\nThe goal is to determine 
---\n# PLEASE UPVOTE IF YOU LIKE IT \u2705\n---\n![Screenshot (3250).png](https://assets.leetcode.com/users/images/29a1896c-a303-4a77-b58e-6d8ce83c737e_1705810439.8498056.png)\n\n---\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe goal is to determine the type of triangle that can be formed based on the given array of three sides. We need to check if the sides satisfy the conditions for forming a triangle and then identify whether it\'s equilateral, isosceles, scalene, or none.\n\n---\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Triangle Inequality Condition Check:**\n\nThe code starts by checking the triangle inequality condition. This condition ensures that the sum of any two sides of a triangle must be greater than the length of the third side.\nIf this condition is not met for the given sides, it means a triangle cannot be formed, and the function returns "none."\n\n**Identifying Triangle Types:**\n\nIf the triangle inequality condition is satisfied, the code proceeds to check the type of triangle.\nFor an equilateral triangle, all sides must be of equal length. This is checked by comparing each side with the other two sides using equality.\nFor a scalene triangle, all sides must be of different lengths. This is checked by ensuring that no two sides are equal.\nIf the triangle is not equilateral or scalene, it is considered isosceles.\n\n**Returning the Result:**\n\nFinally, the function returns the type of triangle identified based on the conditions.\nIf the sides do not form a triangle, it returns "none."\nIf all sides are equal, it returns "equilateral."\nIf all sides are different, it returns "scalene."\nOtherwise, it returns "isosceles."\n\n**In Summary:**\n\nThe code checks if the given sides can form a triangle using the triangle inequality condition. If they can, it further determines the type of triangle (equilateral, isosceles, scalene) based on the lengths of the sides and returns the result. If the sides cannot form a triangle, it returns "none."\n\n---\n\n# Complexity\n- Time complexity: O(1) \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n \n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n---\n\n\n![download.jpeg](https://assets.leetcode.com/users/images/e76b43cf-dafc-4a48-9a68-6f60d3020fb6_1704346279.413626.jpeg)\n\n---\n\n# Code\nC++\n```\nclass Solution {\npublic:\n    // Function to determine the type of triangle based on given sides\n    string triangleType(vector<int>& nums) {\n        // Step 1: Check the triangle inequality condition\n        if (!((nums[0] + nums[1] > nums[2]) && (nums[0] + nums[2] > nums[1]) && (nums[2] + nums[1] > nums[0])))\n            return "none";  // If the sides do not satisfy the triangle inequality, return "none"\n\n        // Step 2: Check if all sides are equal (equilateral)\n        if (nums[0] == nums[1] && nums[1] == nums[2])\n            return "equilateral";  // If all sides are equal, return "equilateral"\n        else if (nums[0] != nums[1] && nums[0] != nums[2] && nums[1] != nums[2])\n            return "scalene";  // If no two sides are equal, return "scalene"\n\n        // Step 3: If not equilateral or scalene, it is isosceles\n        return "isosceles";  // Return "isosceles" as the default option\n    }\n};\n\n```\n\n---\nPython3\n```\nclass Solution:\n    # Function to determine the type of triangle based on given sides\n    def triangleType(self, nums: List[int]) -> str:\n        # Step 1: Check the triangle inequality condition\n        if not (nums[0] + nums[1] > nums[2] and nums[0] + nums[2] > nums[1] and nums[2] + nums[1] > nums[0]):\n            return "none"  # If the sides do not satisfy the triangle inequality, return "none"\n\n        # Step 2: Check if all sides are equal (equilateral)\n        if nums[0] == nums[1] == nums[2]:\n            return "equilateral"  # If all sides are equal, return "equilateral"\n        elif nums[0] != nums[1] and nums[0] != nums[2] and nums[1] != nums[2]:\n            return "scalene"  # If no two sides are equal, return "scalene"\n\n        # Step 3: If not equilateral or scalene, it is isosceles\n        return "isosceles"  # Return "isosceles" as the default option\n\n```\n\n---\nJava\n```\npublic class Solution {\n    // Function to determine the type of triangle based on given sides\n    public String triangleType(int[] nums) {\n        // Step 1: Check the triangle inequality condition\n        if (!(nums[0] + nums[1] > nums[2] && nums[0] + nums[2] > nums[1] && nums[2] + nums[1] > nums[0]))\n            return "none";  // If the sides do not satisfy the triangle inequality, return "none"\n\n        // Step 2: Check if all sides are equal (equilateral)\n        if (nums[0] == nums[1] && nums[1] == nums[2])\n            return "equilateral";  // If all sides are equal, return "equilateral"\n        else if (nums[0] != nums[1] && nums[0] != nums[2] && nums[1] != nums[2])\n            return "scalene";  // If no two sides are equal, return "scalene"\n\n        // Step 3: If not equilateral or scalene, it is isosceles\n        return "isosceles";  // Return "isosceles" as the default option\n    }\n} \n```\n
['Python', 'C++', 'Java', 'Python3']