[Python] 3.16
class Solution:
def maximalSquare(self, matrix: List[List[str]]) -> int:
row = len(matrix)
col = len(matrix[0])
if row == 0 and col == 0:
return 0
else:
dp = [[0] * col for x in range(row)]
maxSide = 0
for i in range(row):
for j in range(col):
if matrix[i][j] == '1':
if i == 0 or j == 0:
dp[i][j] = 1
else:
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
maxSide = max(maxSide, dp[i][j])
return maxSide ** 2

class Solution:
def trap(self, height: List[int]) -> int:
n = len(height)
lmax = [height[0]] + [0] * (n - 1)
rmax = [0] * (n - 1) + [height[-1]]
N = 0
for i in range(1, n):
lmax[i] = max(lmax[i - 1],height[i])
for j in range(n - 2, -1, -1):
rmax[j] = max(rmax[j + 1],height[j])
for k in range(n):
N += min(rmax[k], lmax[k]) - height[k]
return N

相关推荐
ubuntu16.04升级Python3.5到Python3.7的方法步骤
主要介绍了ubuntu16.04升级Python3.5到Python3.7的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
python 3.10.16 windows install 安装包
编译的 python 3.10.16 windows install 安装包
将 Ubuntu 16 和 18 上的 python 升级到最新 python3.8 的方法教程
主要介绍了如何将 Ubuntu 16 和 18 上的 python 升级到最新 3.8 版,本文通过实例代码相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
ubuntu16.04安装python3.6.docx
主要解决安装过程报错,有完整的安装过程。 python-3.6/ubuntu/dists/xenial/main/binary-amd64/Packages 403 Err:7 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 Packages 403 Forbidden [IP: 91.189.95.83 80] W: The repository 'http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial Release' does not have a Release file. N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use. N: See apt-secure(8) manpage for repository creation and user configuration details. E: Failed to fetch http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu/dists/xenial/main/binary-amd64/Packages 403 Forbidden [IP: 91.189.95.83 80] E: Some index files failed to download. They have been ignored, or old ones used instead. Reading package lists... Done E: The repository 'http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
python3.4 将16进制转成字符串的实例
将socket收到的16进制转成字符串 def hex_to_str(b): s = '' for i in b: s += '{0:0>2}'.format(str(hex(i))[2:]) return(s) 以上这篇python3.4 将16进制转成字符串的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。 您可能感兴趣的文章:python字符串替换第一个字符串的方法Python实现将字符串的首字母变为大写,其余都变为小写的方法python2和python3在处理字符串上的区别详


