Sorting + triangle Check. But only iterate 33 elements.
Intuition\n Describe your first thoughts on how to solve this problem. \n- You can find many solutions with a sorting + linear iteration of array.\n- But I clai
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- You can find many solutions with a sorting + linear iteration of array.\n- But I claim that we only need to iterate 33 max elements to find a triangle with max perimeter or return 0;\n- Why becoz, fibo(33)=2178309, and it is a seq which does not obey the triangle rule but almost try to do. (f(n-2)+f(n-1)=f(n))=(a+b=c).\n- So, If our max element is given in constraints that it is 1e6, We only need to check 33 elements. For more clarification, you can try to simulate all cases.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(NlogN + 33)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int largestPerimeter(vector<int>& nums) {\n        int n=nums.size();\n        sort(nums.rbegin(),nums.rend());\n        int sz=min(32,n-2);\n        for(int i=0;i<sz;i++)\n        {\n            if(nums[i]<nums[i+1]+nums[i+2])return nums[i]+nums[i+1]+nums[i+2];\n        }\n        return 0;\n    }\n};\n```
['Math', 'Sorting', 'C++']