ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

2026.9.28

2026.9.28 84 柱状图中最大的矩形class Solution: def largestRectangleArea(self, heights: list[int]) - int: nlen(heights) left[-1]*n right[n]*n st[] for i,h in enumerate(heights): while st and hheights[st[-1]]:st.pop() if st:left[i]st[-1] st.append(i) st.clear() for i in range(n-1,-1,-1): hheights[i] while st and hheights[st[-1]]:st.pop() if st:right[i]st[-1] st.append(i) ans0 for i,j,h in zip(left,right,heights): ansmax(ans,(j-i-1)*h) return ans198 打家劫舍class Solution: def rob(self, nums: List[int]) - int: f0f10 for x in nums: f0,f1f1,max(f1,f0x) return f1118 杨辉三角class Solution: def generate(self, numRows: int) - list[list[int]]: c[[1]*(n1) for n in range(numRows)] for i in range(2,numRows): for j in range(1,i): c[i][j]c[i-1][j]c[i-1][j-1] return c
返回列表