| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.TypeOfTriangle; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class TypeOfTriangleMath : ITypeOfTriangle |
| | 16 | | { |
| | 17 | | private const string Equilateral = "equilateral"; |
| | 18 | | private const string Scalene = "scalene"; |
| | 19 | | private const string Isosceles = "isosceles"; |
| | 20 | | private const string None = "none"; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Time complexity - O(1) |
| | 24 | | /// Space complexity - O(1) |
| | 25 | | /// </summary> |
| | 26 | | /// <param name="nums"></param> |
| | 27 | | /// <returns></returns> |
| | 28 | | public string TriangleType(int[] nums) |
| 9 | 29 | | { |
| 9 | 30 | | if (nums[0] + nums[1] <= nums[2] || nums[1] + nums[2] <= nums[0] || nums[2] + nums[0] <= nums[1]) |
| 1 | 31 | | { |
| 1 | 32 | | return None; |
| | 33 | | } |
| | 34 | |
|
| 8 | 35 | | if (nums[0] == nums[1] && nums[1] == nums[2]) |
| 1 | 36 | | { |
| 1 | 37 | | return Equilateral; |
| | 38 | | } |
| | 39 | |
|
| 7 | 40 | | if (nums[0] == nums[1] || nums[1] == nums[2] || nums[2] == nums[0]) |
| 6 | 41 | | { |
| 6 | 42 | | return Isosceles; |
| | 43 | | } |
| | 44 | |
|
| 1 | 45 | | return Scalene; |
| 9 | 46 | | } |
| | 47 | | } |