leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | e03b706c90a9c08d7c1af8013ec1d05a937bf3fc |
parent | e321f5185bb80c85ae2867eeba07125b55060f98 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Fri, 20 Dec 2024 11:01:35 +0100 |
1 Random Problem
Diffstat:A | Problems/1944.cpp | | | +++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/1944.cpp b/Problems/1944.cpp
@@ -0,0 +1,23 @@
class Solution {
public:
vector<int> canSeePersonsCount(const vector<int> &heights) const {
const int n = size(heights);
vector<int> res(n);
stack<int> st;
for (int i = n - 1; i >= 0; i--) {
const int h = heights[i];
int run = 0;
while (!st.empty() && h >= st.top()) {
st.pop();
run++;
}
res[i] = run + !st.empty();
st.push(h);
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -1149,6 +1149,7 @@ reference and a base for solving problems.
| 1937 | Medium | [Maximum Number of Points with Cost](Problems/1937.cpp) |
| 1942 | Medium | [The Number of the Smallest Unoccupied Chair](Problems/1942.cpp) |
| 1943 | Medium | [Describe the Painting](Problems/1943.cpp) |
| 1944 | Hard | [Number of Visible People in a Queue](Problems/1944.cpp) |
| 1945 | Easy | [Sum of Digits of String After Convert](Problems/1945.cpp) |
| 1947 | Medium | [Maximum Compatibility Score Sum](Problems/1947.cpp) |
| 1954 | Medium | [Minimum Garden Perimeter to Collect Enough Apples](Problems/1954.cpp) |