fix(two-pointers): code formatting
This commit is contained in:
parent
5549a1912f
commit
b406a073c9
1 changed files with 18 additions and 16 deletions
|
|
@ -73,16 +73,19 @@
|
||||||
</p>
|
</p>
|
||||||
<div class="post-code">
|
<div class="post-code">
|
||||||
<pre><code class="language-python">def maxArea(height: list[int]) -> int:
|
<pre><code class="language-python">def maxArea(height: list[int]) -> int:
|
||||||
area = 0
|
ans = 0
|
||||||
l, r = 0, len(height) - 1
|
l, r = 0, len(height) - 1
|
||||||
|
|
||||||
while l < r:
|
while l < r:
|
||||||
width, min_height = r - l, min(height[l], height[r])
|
width, min_height = r - l, min(height[l], height[r])
|
||||||
area = max(area, width * min_height)
|
ans = max(ans, width * min_height)
|
||||||
|
|
||||||
while l < r and height[l] <= min_height:
|
while l < r and height[l] <= min_height:
|
||||||
l += 1
|
l += 1
|
||||||
while l < r and height[r] <= min_height:
|
while l < r and height[r] <= min_height:
|
||||||
r -= 1
|
r -= 1
|
||||||
return area</code></pre>
|
|
||||||
|
return ans</code></pre>
|
||||||
</div>
|
</div>
|
||||||
<h3>
|
<h3>
|
||||||
<a
|
<a
|
||||||
|
|
@ -117,25 +120,24 @@
|
||||||
</ol>
|
</ol>
|
||||||
<div class="post-code">
|
<div class="post-code">
|
||||||
<pre><code class="language-python">def minimum_rescue_boats(people: list[int], limit: int) -> int:
|
<pre><code class="language-python">def minimum_rescue_boats(people: list[int], limit: int) -> int:
|
||||||
boats = 0
|
ans = 0
|
||||||
light = 0
|
l, r = 0, len(people) - 1
|
||||||
heavy = len(people) - 1
|
|
||||||
|
|
||||||
people.sort()
|
people.sort()
|
||||||
|
|
||||||
while light <= heavy:
|
while l <= r:
|
||||||
if light == heavy:
|
if l == r:
|
||||||
boats += 1
|
ans += 1
|
||||||
break
|
break
|
||||||
elif people[light] + people[heavy] <= limit:
|
elif people[l] + people[r] <= limit:
|
||||||
boats += 1
|
ans += 1
|
||||||
light += 1
|
l += 1
|
||||||
heavy -= 1
|
r -= 1
|
||||||
else:
|
else:
|
||||||
boats += 1
|
ans += 1
|
||||||
heavy -= 1
|
r -= 1
|
||||||
|
|
||||||
return boats</code></pre>
|
return ans</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue