[JAVA]☕ | Easy and Explained Solution ❤ | Speed Beats 99.7% ✔️
Approach\n Describe your approach to solving the problem. \nThe solution involves a simple iteration of the array after sorting it with  with Arrays.sort(). \n\
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe solution involves a simple **iteration of the array** after **sorting** it with  with `Arrays.sort()`. \n\n*At each iteration* we have to compare the three greater values:\n1) If **is a triangle**, return  the perimeter. This happen if *the sum of two sides is larger than the last side*;\n2) If **is not a triangle**, start the next iteration looking at the values at position `i--`;\n\n**Note:** In Java, we have **different ways to sort an array**, usually the best are `Arrays.sort()` and `Collection.sort()`. When we are working with primitive datatypes like int, `Arrays.sort()` proves to be way more time efficient than `Collections.sort()`\n \n**Arrays.sort():** make the sort inside the array.\n**Collections.sort():** is used mainly to sort list, this means that it make more steps to do the same opeartion.\n\n# Complexity\n- **Time complexity:** $O(n*log(n))$\n- **Speed Beats:** 99.7%\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- **Space complexity:** $O(n)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int largestPerimeter(int[] nums) {\n        \n        Arrays.sort(nums);\n\n        for (int i = nums.length - 1; i >= 2; i--)\n            if (nums[i] < nums[i-1] + nums[i-2])\n                return nums[i] + nums[i-1] + nums[i-2];\n            \n        return 0;\n    }\n}\n```
['Array', 'Greedy', 'Sorting', 'Java']