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 0000000000000000000000000000000000000000..7957b2d8f3f915695b98383ba768e2cc58c5029f --- /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