Re: [闲聊] 每日leetcode

楼主: oinishere (是oin捏)   2024-04-12 11:10:07
这题我是用stack做
一样是找两边最高的 让他们装水
然后要两个stack
不然会有没装到水的地方

class Solution {
public:
int trap(vector<int>& height)
{
int water = 0;
int len = height.size();
vector<int> paper;
vector<int> paper2;
for(int i = 0 ; i < len ; i ++)
{
paper.push_back(i);
int tall = 0;
int talli = 0;
if(paper.size() > 1 && height[paper[0]] <= height[paper[paper.size()
-1]])
{
tall = min(height[paper[0]] , height[paper[paper.size()-1]] );
talli = i;
for(int j = paper[0]+1 ; j < paper[paper.size()-1] ; j ++)
{
water += tall - height[j];
//cout << tall << " - " << height[j] << " (" << j << endl;
}
paper.clear();
paper.push_back(i);
}
}
for(int i = paper.size()-1 ; i >= 0 ; i
作者: wwndbk (黑人问号)   2024-04-12 11:11:00
大师
作者: wu10200512 (廷廷)   2024-04-12 11:11:00
为啥要取名叫paper
楼主: oinishere (是oin捏)   2024-04-12 11:12:00
因为我喜欢拿纸画画写题目 算我的习惯画画写题目想东西都拿纸
作者: JIWP (JIWP)   2024-04-12 11:13:00
这题去年就写过了
楼主: oinishere (是oin捏)   2024-04-12 11:13:00
我去年是用c写的 解法跟现在差不多
作者: DJYOSHITAKA (Evans)   2024-04-12 11:15:00
大师
作者: JIWP (JIWP)   2024-04-12 11:15:00
还不是卖py
作者: SecondRun (雨夜琴声)   2024-04-12 12:09:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com