File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
solution/0700-0799/0739.Daily Temperatures Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,30 @@ class Solution {
6666}
6767```
6868
69+ ### ** C++**
70+
71+ <!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+ ``` cpp
74+ class Solution {
75+ public:
76+ vector<int > dailyTemperatures(vector<int >& T) {
77+ int n = T.size();
78+ vector<int > ans(n);
79+ stack<int > s;
80+ for(int i = 0; i < n; ++i) {
81+ while(!s.empty() && T[ s.top()] < T[ i] ) {
82+ int pre = s.top();
83+ s.pop();
84+ ans[ pre] = i - pre;
85+ }
86+ s.push(i);
87+ }
88+ return ans;
89+ }
90+ };
91+ ```
92+
6993### **...**
7094
7195```
Original file line number Diff line number Diff line change @@ -62,6 +62,30 @@ class Solution {
6262}
6363```
6464
65+ ### ** C++**
66+
67+ <!-- 这里可写当前语言的特殊实现逻辑 -->
68+
69+ ``` cpp
70+ class Solution {
71+ public:
72+ vector<int > dailyTemperatures(vector<int >& T) {
73+ int n = T.size();
74+ vector<int > ans(n);
75+ stack<int > s;
76+ for(int i = 0; i < n; ++i) {
77+ while(!s.empty() && T[ s.top()] < T[ i] ) {
78+ int pre = s.top();
79+ s.pop();
80+ ans[ pre] = i - pre;
81+ }
82+ s.push(i);
83+ }
84+ return ans;
85+ }
86+ };
87+ ```
88+
6589### **...**
6690
6791```
Original file line number Diff line number Diff line change 1+ /* *
2+ * Author: Moriarty12138
3+ */
4+ class Solution {
5+ public:
6+ vector<int > dailyTemperatures (vector<int >& T) {
7+ int n = T.size ();
8+ vector<int > ans (n);
9+ stack<int > s;
10+ for (int i = 0 ; i < n; ++i) {
11+ while (!s.empty () && T[s.top ()] < T[i]) {
12+ int pre = s.top ();
13+ s.pop ();
14+ ans[pre ] = i - pre ;
15+ }
16+ s.push (i);
17+ }
18+ return ans;
19+ }
20+ };
You can’t perform that action at this time.
0 commit comments