From f8e28caecadebd1f1a217c1a2a0d7b5f21e965d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B6=9B2005?= <3215911784@qq.com> Date: Mon, 22 Sep 2025 20:57:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E5=91=A8=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LC739_\345\210\230\346\266\233.cpp" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "topic01/submit/LC739_\345\210\230\346\266\233.cpp" diff --git "a/topic01/submit/LC739_\345\210\230\346\266\233.cpp" "b/topic01/submit/LC739_\345\210\230\346\266\233.cpp" new file mode 100644 index 0000000..08db692 --- /dev/null +++ "b/topic01/submit/LC739_\345\210\230\346\266\233.cpp" @@ -0,0 +1,36 @@ + +class Solution { +public: + vectordailyTemperatures(vector& temperatures) { + int n = temperatures.size(); + vectorans(n); + stackst; + for (int i = 0;i < n;i++) { + while (!st.empty() && temperatures[i] > temperatures[st.top()]) { + + ans[st.top()] = i - st.top(); + st.pop(); + } + st.push(i); + } + return ans; + } +} + +class Solution { +public: + vector dailyTemperatures(vector& temperatures) { + int n = temperatures.size(); + stackst; + vectorans(n, 0); + for (int i = 0;i < n;i++) { + while (!st.empty() && temperatures[i] > temperatures[st.top()]) { + int top = st.top(); + st.pop(); + ans[top] = i - top; + } + st.push(i); + } + return ans; + } +}; \ No newline at end of file -- Gitee From bd661ce46e3701200b6b945af92a13adef7938ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B6=9B2005?= <3215911784@qq.com> Date: Thu, 25 Sep 2025 17:12:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E5=91=A8=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LC1944_\345\210\230\346\266\233.cpp" | 17 +++++++++++++ .../LC1996_\345\210\230\346\266\233.cpp" | 24 +++++++++++++++++++ .../submit/LC42_\345\210\230\346\266\233.cpp" | 23 ++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 "topic01/submit/LC1944_\345\210\230\346\266\233.cpp" create mode 100644 "topic01/submit/LC1996_\345\210\230\346\266\233.cpp" create mode 100644 "topic01/submit/LC42_\345\210\230\346\266\233.cpp" diff --git "a/topic01/submit/LC1944_\345\210\230\346\266\233.cpp" "b/topic01/submit/LC1944_\345\210\230\346\266\233.cpp" new file mode 100644 index 0000000..c009ee2 --- /dev/null +++ "b/topic01/submit/LC1944_\345\210\230\346\266\233.cpp" @@ -0,0 +1,17 @@ +class Solution { +public: + vector dailyTemperatures(vector& temperatures) { + int n = temperatures.size(); + stackst; + vectorans(n, 0); + for (int i = 0;i < n;i++) { + while (!st.empty() && temperatures[i] > temperatures[st.top()]) { + int top = st.top(); + st.pop(); + ans[top] = i - top; + } + st.push(i); + } + return ans; + } +}; \ No newline at end of file diff --git "a/topic01/submit/LC1996_\345\210\230\346\266\233.cpp" "b/topic01/submit/LC1996_\345\210\230\346\266\233.cpp" new file mode 100644 index 0000000..b50b465 --- /dev/null +++ "b/topic01/submit/LC1996_\345\210\230\346\266\233.cpp" @@ -0,0 +1,24 @@ +class Solution { +public: + static bool compareProperties(const vector& a, const vector& b) { + if (a[0] == b[0]) { + return a[1] > b[1]; + } + return a[0] < b[0]; + } + + int numberOfWeakCharacters(vector>& properties) { + sort(properties.begin(), properties.end(), Solution::compareProperties); + + stackst; + int ans = 0; + for (auto& p : properties) { + while (!st.empty() && st.top() < p[1]) { + ++ans; + st.pop(); + } + st.push(p[1]); + } + return ans; + } +}; \ No newline at end of file diff --git "a/topic01/submit/LC42_\345\210\230\346\266\233.cpp" "b/topic01/submit/LC42_\345\210\230\346\266\233.cpp" new file mode 100644 index 0000000..2fceca4 --- /dev/null +++ "b/topic01/submit/LC42_\345\210\230\346\266\233.cpp" @@ -0,0 +1,23 @@ +class Solution { +public: + int trap(vector& height) { + int ans = 0; + stackstk; + int n = height.size(); + for (int i = 0;i < n;++i) { + while (!stk.empty() && height[i] > height[stk.top()]) { + int top = stk.top(); + stk.pop(); + if (stk.empty()) { + break; + } + int left = stk.top(); + int currWidth = i - left - 1; + int currHeight = min(height[left], height[i]) - height[top]; + ans += currWidth * currHeight; + } + stk.push(i); + } + return ans; + } +}; \ No newline at end of file -- Gitee