小white刷题记——LeetCodeHot100_11

该算法问题旨在计算数组能构成的最大矩形面积。使用双指针方法,i和j分别代表数组的起始和结束,通过比较height[i]和height[j]确定移动哪个指针,以保证可能的最大面积。在循环中,始终更新最大面积并移动较短边的指针,直到i不小于j为止。
摘要由CSDN通过智能技术生成

读题心路历程:这道题,我感觉其实就是算矩形的最大面积,这个矩形中,数组中的数字为一条边,然后另一条边一定要大于等于这条边,然后再由这两条边在数组中的下标差为矩形的另一条边,然后求出这个数组可以组成矩形的最大面积。所以自然而然的想到了,用 i 和 j 分别表示两条变的位置,然后用 j-i 来表示一条边,用 j 或者 i 中最小的边,表示矩形的另一条边,乘起来就是矩形面积了,然后在遍历过程中,找到最大的就行。

代码:

int maxArea(vector<int>& height) {
//利用类似双指针的方法,首尾分别定义 i 和 j
        int i = 0;
	    int j = height.size() - 1;
	    int maxArea = 0;
//仔细想一下,在移动双指针的时候,每次都要比较 height[i] 和 height[j] 的大小的,所以不需要让 i 移动完一整个数组的,移动一半之后,只需要当 i >= j 的时候停止计算就可以了。
	    while (i<j)
	    {
	    	if (height[i] > height[j])
		    {
		    	maxArea = max(maxArea, height[j] * (j - i));//这块的话,肯定要谁小去移动哪个指针的,因为,移动大的之后,j-i 肯定就更小了,所以矩形肯定会更小了。
		    	j--;
	    	}
		    else {
			    maxArea = max(maxArea, height[i] * (j - i));
		    	i++;
	    	}
	    }
	    return maxArea;
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
“ # 设置按钮的背景颜色 self.m_button1.SetBackgroundColour('#0a74f7') self.m_button1.SetForegroundColour('white') self.m_button2.SetBackgroundColour('#0a74f7') self.m_button2.SetForegroundColour('white') self.m_button3.SetBackgroundColour('#0a74f7') self.m_button3.SetForegroundColour('white') self.m_button4.SetBackgroundColour('#238E23') self.m_button4.SetForegroundColour('white') self.m_button5.SetBackgroundColour('#238E23') self.m_button5.SetForegroundColour('white') self.m_button6.SetBackgroundColour('#238E23') self.m_button6.SetForegroundColour('white') self.m_button7.SetBackgroundColour('#6F4242') self.m_button7.SetForegroundColour('white') self.m_button8.SetBackgroundColour('#6F4242') self.m_button8.SetForegroundColour('white') self.m_button9.SetBackgroundColour('#6F4242') self.m_button9.SetForegroundColour('white') self.m_button10.SetBackgroundColour('#8E6B23') self.m_button10.SetForegroundColour('white') self.m_button11.SetBackgroundColour('#8E6B23') self.m_button11.SetForegroundColour('white') self.m_button12.SetBackgroundColour('#8E6B23') self.m_button12.SetForegroundColour('white') self.m_button13.SetBackgroundColour('#8E6B23') self.m_button13.SetForegroundColour('white') self.m_button14.SetBackgroundColour('#545454') self.m_button14.SetForegroundColour('white') self.m_button15.SetBackgroundColour('#545454') self.m_button15.SetForegroundColour('white') self.m_button16.SetBackgroundColour('#545454') self.m_button16.SetForegroundColour('white') self.m_panel1.SetBackgroundColour('white') # 设置面板的背景颜色”逐行解释代码
06-07
这段代码是用来设置图形用户界面中多个按钮和一个面板的背景和前景颜色的。具体解释如下: - `self.m_button1.SetBackgroundColour('#0a74f7')`:设置按钮1的背景颜色为蓝色。 - `self.m_button1.SetForegroundColour('white')`:设置按钮1的前景颜色为白色。 - `self.m_button2.SetBackgroundColour('#0a74f7')`:设置按钮2的背景颜色为蓝色。 - `self.m_button2.SetForegroundColour('white')`:设置按钮2的前景颜色为白色。 - `self.m_button3.SetBackgroundColour('#0a74f7')`:设置按钮3的背景颜色为蓝色。 - `self.m_button3.SetForegroundColour('white')`:设置按钮3的前景颜色为白色。 - `self.m_button4.SetBackgroundColour('#238E23')`:设置按钮4的背景颜色为绿色。 - `self.m_button4.SetForegroundColour('white')`:设置按钮4的前景颜色为白色。 - `self.m_button5.SetBackgroundColour('#238E23')`:设置按钮5的背景颜色为绿色。 - `self.m_button5.SetForegroundColour('white')`:设置按钮5的前景颜色为白色。 - `self.m_button6.SetBackgroundColour('#238E23')`:设置按钮6的背景颜色为绿色。 - `self.m_button6.SetForegroundColour('white')`:设置按钮6的前景颜色为白色。 - `self.m_button7.SetBackgroundColour('#6F4242')`:设置按钮7的背景颜色为红色。 - `self.m_button7.SetForegroundColour('white')`:设置按钮7的前景颜色为白色。 - `self.m_button8.SetBackgroundColour('#6F4242')`:设置按钮8的背景颜色为红色。 - `self.m_button8.SetForegroundColour('white')`:设置按钮8的前景颜色为白色。 - `self.m_button9.SetBackgroundColour('#6F4242')`:设置按钮9的背景颜色为红色。 - `self.m_button9.SetForegroundColour('white')`:设置按钮9的前景颜色为白色。 - `self.m_button10.SetBackgroundColour('#8E6B23')`:设置按钮10的背景颜色为橙色。 - `self.m_button10.SetForegroundColour('white')`:设置按钮10的前景颜色为白色。 - `self.m_button11.SetBackgroundColour('#8E6B23')`:设置按钮11的背景颜色为橙色。 - `self.m_button11.SetForegroundColour('white')`:设置按钮11的前景颜色为白色。 - `self.m_button12.SetBackgroundColour('#8E6B23')`:设置按钮12的背景颜色为橙色。 - `self.m_button12.SetForegroundColour('white')`:设置按钮12的前景颜色为白色。 - `self.m_button13.SetBackgroundColour('#8E6B23')`:设置按钮13的背景颜色为橙色。 - `self.m_button13.SetForegroundColour('white')`:设置按钮13的前景颜色为白色。 - `self.m_button14.SetBackgroundColour('#545454')`:设置按钮14的背景颜色为灰色。 - `self.m_button14.SetForegroundColour('white')`:设置按钮14的前景颜色为白色。 - `self.m_button15.SetBackgroundColour('#545454')`:设置按钮15的背景颜色为灰色。 - `self.m_button15.SetForegroundColour('white')`:设置按钮15的前景颜色为白色。 - `self.m_button16.SetBackgroundColour('#545454')`:设置按钮16的背景颜色为灰色。 - `self.m_button16.SetForegroundColour('white')`:设置按钮16的前景颜色为白色。 - `self.m_panel1.SetBackgroundColour('white')`:设置面板1的背景颜色为白色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值