Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

976. Largest Perimeter Triangle leetcode solution in c++

class Solution {
public:
    int largestPerimeter(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        for(int i=nums.size()-3;i>=0;i--)
        {
            if(nums[i]+nums[i+1]>nums[i+2])
                return nums[i] + nums[i+1] + nums[i+2];
        }
        return 0;
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Largest #Perimeter #Triangle #leetcode #solution
ADD COMMENT
Topic
Name
9+9 =