diff --git "a/exercise/LC 1944_\351\231\210\346\230\240\350\276\211.cpp" "b/exercise/LC 1944_\351\231\210\346\230\240\350\276\211.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..652032b6047ebd459e1150b192334747b17f926d --- /dev/null +++ "b/exercise/LC 1944_\351\231\210\346\230\240\350\276\211.cpp" @@ -0,0 +1,21 @@ +class Solution { +public: + vector canSeePersonsCount(vector& heights) { + int n=heights.size(); + vectorstk; + vectorans(n, 0); + + for(int i=n-1;i>=0;i--){ + int h1=heights[i]; + while(!stk.empty()&&stk.back()& height) { + int n =height.size(); + stackst; + int nums=0; + for(int i=0;iheight[st.top()]){ + int topIdx=st.top(); + st.pop(); + if(st.empty()){ + break; + } + int l = st.top(); + int currWigth = i-l-1; + int currHeight = min(height[l],height[i])-height[topIdx]; + nums += currWigth * currHeight; + } + st.push(i); + } + return nums; + } +}; diff --git "a/topic01/submit/LC 496_\351\231\210\346\230\240\350\276\211.cpp" "b/topic01/submit/LC 496_\351\231\210\346\230\240\350\276\211.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..a8137ea1b12accf21722b0ba43b2c83b69898d53 --- /dev/null +++ "b/topic01/submit/LC 496_\351\231\210\346\230\240\350\276\211.cpp" @@ -0,0 +1,22 @@ +class Solution { +public: + vector nextGreaterElement(vector& nums1, vector& nums2) { + int n1=nums1.size(); + int n2=nums2.size(); + stackst; + unordered_maphash; + vectorans(n1); + for(int i=n2-1;i>=0;--i){ //单调栈 + int num=nums2[i]; + while(!st.empty() && num>=st.top()){ + st.pop(); + } + hash[num]=st.empty()?-1:st.top(); + st.push(num); //单调栈结束,把答案存入哈希表 + } + for(int i=0;i nextGreaterElements(vector& nums) { + int n=nums.size(); + stackst; + vectorres(n,-1); + for(int i=0;inums[st.top()]){ + int topIdx=st.top(); + st.pop(); + res[topIdx]=nums[i%n]; + } + st.push(i%n); + } + return res; + } +}; diff --git "a/topic01/submit/LC 739_\351\231\210\346\230\240\350\276\211.cpp" "b/topic01/submit/LC 739_\351\231\210\346\230\240\350\276\211.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..4e110fd7311862688e1e6c1bfb48712ec911e41e --- /dev/null +++ "b/topic01/submit/LC 739_\351\231\210\346\230\240\350\276\211.cpp" @@ -0,0 +1,17 @@ +class Solution { +public: + vector dailyTemperatures(vector& temperatures) { + int n=temperatures.size(); + vectorans(n,0); + stackst; + for(int i=0;itemperatures[st.top()]){ + int topIdx=st.top(); + ans[topIdx]=i-topIdx; + st.pop(); + } + st.push(i); + } + return ans; + } +};