From fe3333957ef4a6e811b7bece09d196a538c12e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=A5=96=E6=BA=90?= <15692551+liang-zuyuan@user.noreply.gitee.com> Date: Thu, 18 Sep 2025 20:43:29 +0800 Subject: [PATCH] =?UTF-8?q?20250918=E7=AC=AC=E4=B8=80=E5=91=A8=E7=BB=83?= =?UTF-8?q?=E4=B9=A0=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\346\242\201\347\245\226\346\272\220.cpp" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "topic01/submit/LC1944_\346\242\201\347\245\226\346\272\220.cpp" diff --git "a/topic01/submit/LC1944_\346\242\201\347\245\226\346\272\220.cpp" "b/topic01/submit/LC1944_\346\242\201\347\245\226\346\272\220.cpp" new file mode 100644 index 0000000..7957b2d --- /dev/null +++ "b/topic01/submit/LC1944_\346\242\201\347\245\226\346\272\220.cpp" @@ -0,0 +1,23 @@ +class Solution { +public: + vector canSeePersonsCount(vector& heights) { + int n = heights.size(); + vector answer(n, 0); + stack stk; + + for (int i = n - 1; i >= 0; --i) { + int count = 0; + while (!stk.empty() && heights[i] > stk.top()) { + count++; + stk.pop(); + } + if (!stk.empty()) { + count++; + } + answer[i] = count; + stk.push(heights[i]); + } + + return answer; + } +}; \ No newline at end of file -- Gitee