快速排序(python)
来源:互联网 发布:arm linux 内核头文件 编辑:程序博客网 时间:2024/06/05 06:45
class Solution:
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
self.QSort(height,0,len(height)-1)
return height[len(height)-2]*height[len(height)-2]
def QSort(self,height,low,high):
if low<high:
pivot = self.Partition(height,low,high)
self.QSort(height,low,pivot-1)
self.QSort(height,pivot+1,high)
def Partition(self,height,low,high):
pivotkey=height[low]
while low<high:
while(low<high and height[high] >=pivotkey):
high = high-1
height[low]=height[high]
while(low<high and height[low] <=pivotkey):
low = low +1
height[high]=height[low]
height[low]=pivotkey
return low
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
self.QSort(height,0,len(height)-1)
return height[len(height)-2]*height[len(height)-2]
def QSort(self,height,low,high):
if low<high:
pivot = self.Partition(height,low,high)
self.QSort(height,low,pivot-1)
self.QSort(height,pivot+1,high)
def Partition(self,height,low,high):
pivotkey=height[low]
while low<high:
while(low<high and height[high] >=pivotkey):
high = high-1
height[low]=height[high]
while(low<high and height[low] <=pivotkey):
low = low +1
height[high]=height[low]
height[low]=pivotkey
return low
阅读全文
0 0
- 快速排序(python)
- 快速排序(Python)
- 快速排序(python)
- 快速排序(python)
- 快速排序(Python实现)
- 快速排序(python实现)
- Python--排序--快速排序
- [排序] 快速排序(Python)
- 【python】python数据结构(七)——排序:快速排序
- Python(8) python中的冒泡排序、快速排序
- (四)快速排序-python实现
- 快速排序的实现(python)
- 快速排序及实现(python)
- 学Python(3)—快速排序
- python快速排序
- 快速排序Python实现
- python快速排序
- python实现快速排序
- 《TP5.0学习笔记---模型篇(三)》
- Python自然语言处理 6 学习分类文本
- MySQL(六)表操作
- PyCharm2017.2.4 + Python3.5.2 + PYQT5 + Qt Designer5.8配置
- 【Unity&GameSparks】与Photon互补的免费强大的后端GameSparks(大陆稳定低延迟)附中文注释云端代码Typings
- 快速排序(python)
- java:常用包
- ubuntu16.04 opencv2配置
- numpy: np.where
- Pascal 整数字符,实数类型
- IntelliJ IDEA windows安装
- 【MySql】Sql优化(一)——Sql执行流程
- 堡垒机的初步了解
- Python内置函数-map()函数