diff --git a/Stack/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid.cpp b/Stack/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid.cpp new file mode 100644 index 000000000..6d38951d8 --- /dev/null +++ b/Stack/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid/2282.Number-of-People-That-Can-Be-Seen-in-a-Grid.cpp @@ -0,0 +1,52 @@ +class Solution { +public: + vector> seePeople(vector>& heights) + { + int m = heights.size(), n = heights[0].size(); + vector>rets(m, vector(n,0)); + + for (int i=0; istk; + for (int j=0; j= heights[i][stk.top()]) + { + rets[i][stk.top()]++; + lastRemove = heights[i][stk.top()]; + stk.pop(); + } + if (!stk.empty() && lastRemove != heights[i][j]) + { + rets[i][stk.top()]++; + } + stk.push(j); + } + + } + + for (int j=0; jstk; + for (int i=0; i= heights[stk.top()][j]) + { + rets[stk.top()][j]++; + lastRemove = heights[stk.top()][j]; + stk.pop(); + } + if (!stk.empty() && lastRemove != heights[i][j]) + { + rets[stk.top()][j]++; + } + stk.push(i); + } + } + + return rets; + + } +};