Skip to content

Commit 4790723

Browse files
committed
976 accepted. 1776 ms
1 parent 3b43239 commit 4790723

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Algorithms/0976.largest-perimeter-triangle/largest-perimeter-triangle.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import "sort"
44

55
func largestPerimeter(A []int) int {
66
size := len(A)
7-
sort.Ints(A)
8-
res := 0
7+
sort.Sort(sort.Reverse(sort.IntSlice(A)))
98
for i := 0; i < size; i++ {
109
a := A[i]
1110
for j := i + 1; j < size; j++ {
1211
b := A[j]
1312
for k := j + 1; k < size; k++ {
1413
c := A[k]
15-
if isOK(a, b, c) {
16-
res = max(res, a+b+c)
14+
if a < b+c {
15+
return a + b + c
1716
}
1817
}
1918
}
2019
}
21-
return res
20+
return 0
2221
}
2322

2423
func isOK(a, b, c int) bool {

0 commit comments

Comments
 (0)