![JAR search and dependency download from the Maven repository](/logo.png)
g0901_1000.s0976_largest_perimeter_triangle.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0901_1000.s0976_largest_perimeter_triangle
// #Easy #Array #Math #Sorting #Greedy #Programming_Skills_I_Day_3_Conditional_Statements
// #2023_05_08_Time_304_ms_(33.33%)_Space_58.4_MB_(10.00%)
class Solution {
fun largestPerimeter(nums: IntArray): Int {
nums.sort()
for (i in nums.size - 1 downTo 2) {
if (nums[i] < nums[i - 1] + nums[i - 2]) {
return nums[i] + nums[i - 1] + nums[i - 2]
}
}
return 0
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy