File tree 3 files changed +68
-0
lines changed
solution/0700-0799/0739.Daily Temperatures
3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,30 @@ class Solution {
66
66
}
67
67
```
68
68
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
+
69
93
### **...**
70
94
71
95
```
Original file line number Diff line number Diff line change @@ -62,6 +62,30 @@ class Solution {
62
62
}
63
63
```
64
64
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
+
65
89
### **...**
66
90
67
91
```
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