fix(two-pointers): code formatting

This commit is contained in:
Barrett Ruth 2024-06-17 13:55:44 -05:00
parent 5549a1912f
commit b406a073c9

View file

@ -73,16 +73,19 @@
</p>
<div class="post-code">
<pre><code class="language-python">def maxArea(height: list[int]) -> int:
area = 0
ans = 0
l, r = 0, len(height) - 1
while l < 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:
l += 1
while l < r and height[r] <= min_height:
r -= 1
return area</code></pre>
return ans</code></pre>
</div>
<h3>
<a
@ -117,25 +120,24 @@
</ol>
<div class="post-code">
<pre><code class="language-python">def minimum_rescue_boats(people: list[int], limit: int) -> int:
boats = 0
light = 0
heavy = len(people) - 1
ans = 0
l, r = 0, len(people) - 1
people.sort()
while light <= heavy:
if light == heavy:
boats += 1
while l <= r:
if l == r:
ans += 1
break
elif people[light] + people[heavy] <= limit:
boats += 1
light += 1
heavy -= 1
elif people[l] + people[r] <= limit:
ans += 1
l += 1
r -= 1
else:
boats += 1
heavy -= 1
ans += 1
r -= 1
return boats</code></pre>
return ans</code></pre>
</div>
</article>
</div>