Skip to content

Commit

Permalink
Time: 200 ms (58.19%) | Memory: 66.9 MB (11.30%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 15, 2024
1 parent cfe03fc commit 792e5ee
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @param {number[]} nums
* @return {number}
*/
var largestPerimeter = function(nums) {
let solution = new Solution();
return solution.largestPerimeter(nums);
};

class Solution {
largestPerimeter(nums) {
nums.sort((a, b) => a - b);
let sum = 0;
let ans = -1;

for (let i = 0; i < nums.length; i++) {
if (nums[i] < sum) {
ans = nums[i] + sum;
}
sum += nums[i];
}

return ans;
}
}

0 comments on commit 792e5ee

Please sign in to comment.