From 682914e726759a6a246872c3cb151a8c5535cf63 Mon Sep 17 00:00:00 2001 From: wzw <15369625+wuzhiweinb@user.noreply.gitee.com> Date: Fri, 19 Sep 2025 19:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8A=9B=E6=89=A342=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\345\220\264\345\277\227\345\250\201.cpp" | 25 +++++++++++++++++++ ..._\345\220\264\345\277\227\345\250\201.cpp" | 0 2 files changed, 25 insertions(+) create mode 100644 "topic01/submit/LC0042_\345\220\264\345\277\227\345\250\201.cpp" create mode 100644 "topic01/submit/LC1944_\345\220\264\345\277\227\345\250\201.cpp" diff --git "a/topic01/submit/LC0042_\345\220\264\345\277\227\345\250\201.cpp" "b/topic01/submit/LC0042_\345\220\264\345\277\227\345\250\201.cpp" new file mode 100644 index 0000000..40ed6ad --- /dev/null +++ "b/topic01/submit/LC0042_\345\220\264\345\277\227\345\250\201.cpp" @@ -0,0 +1,25 @@ +class Solution { +public: + int trap(vector& height) { + vector sta; + int i = 0;int sum = 0; + while(i < height.size()) + { + while(!sta.empty() && height[i] > height[sta.back()]) + { + int top = sta.back(); + sta.pop_back(); + if(sta.empty())break; + int instance = i - sta.back() - 1; + int he = min(height[i],height[sta.back()]) - height[top]; + sum +=he * instance; + } + sta.push_back(i++); + } + return sum; + + } +}; + + + diff --git "a/topic01/submit/LC1944_\345\220\264\345\277\227\345\250\201.cpp" "b/topic01/submit/LC1944_\345\220\264\345\277\227\345\250\201.cpp" new file mode 100644 index 0000000..e69de29 -- Gitee