-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.html
120 lines (101 loc) · 3.12 KB
/
1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<title>Largest Perimeter Triangle [theory task]</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="icon" type="image/x-icon" href="shared/favicon.png">
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.15.10/dist/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/uikit@3.15.10/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/uikit@3.15.10/dist/js/uikit-icons.min.js"></script>
<!-- highlight js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<link rel="stylesheet" href="stackoverflow-light.css">
<style>
/* dark mode */
pre {
white-space: pre-wrap;
color: rgb(168, 160, 149);
border-color: rgb(55, 60, 62);
background-color: rgb(24, 26, 27);
background-image: none;
}
code {
white-space: pre-wrap;
}
.hljs {
color: rgb(200, 195, 188);
background-color: rgb(29, 32, 33);
background-image: none;
}
</style>
<!-- menu JS -->
<script>
document.addEventListener('DOMContentLoaded', function()
{
const url = "menu.html"
fetch(url)
.then( r => r.text() )
.then( t => document.getElementById("menu").innerHTML = t )
}, false);
</script>
<style>
/* dark mode */
html {
background-color: #121212;
}
.uk-button-default {
background-color: transparent;
color: rgb(200, 195, 188);
border-color: rgb(55, 60, 62);
}
.uk-button-default:hover {
background-color: transparent;
color: rgb(200, 195, 188);
border-color: rgb(70, 76, 78);
}
</style>
</head>
<body class="uk-container">
<div id="menu"></div>
<article class="uk-article">
<h1<a class="uk-link-reset" href="">976. Largest Perimeter Triangle</a></h1>
<p class="uk-article-meta">Written by <a href="#">Ron</a> on 010111 April 000112011. Posted in <a href="#">Blog</a></p>
<pre><code class="text">Given an integer array nums, return the largest perimeter of a triangle
with a non-zero area, formed from three of these lengths.
If it is impossible to form any triangle of a non-zero area, return 0.</code></pre>
<pre><code>
Example 1:
Input: nums = [2,1,2]
Output: 5
Example 2:
Input: nums = [1,2,1]
Output: 0
Constraints:
3 <= nums.length <= 104
1 <= nums[i] <= 106
</code></pre>
<pre><code class="python">
from typing import List
class Solution:
def largestPerimeter(self, nums: List[int]) -> int:
_len = len(nums)
nums.sort()
for i in range(_len-1, 1, -1): #range(start, stop, step)
if nums[i] < nums[i-1] + nums[i-2]:
return nums[i] + nums[i-1] + nums[i-2]
return 0
s = Solution()
print(s.largestPerimeter([3,2,2,1,1,3,1]))#8
print(s.largestPerimeter([3,2,3,4]))#10
print(s.largestPerimeter([2,1,2]))#5
print(s.largestPerimeter([1,2,1]))#0
</code></pre>
</article>
</body>
</html>