Skip to content

feat: add solution to leetcode No.0033 No.0081 #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add solutions to leetcode No.0739.Daily Temperatures
  • Loading branch information
gqjia committed Apr 6, 2021
commit 19d0d4b53eb70b72fb4dd1db7426b4e56622ed4f
24 changes: 24 additions & 0 deletions solution/0700-0799/0739.Daily Temperatures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ class Solution {
}
```

### **C++**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```cpp
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& T) {
int n = T.size();
vector<int> ans(n);
stack<int> s;
for(int i = 0; i < n; ++i) {
while(!s.empty() && T[s.top()] < T[i]) {
int pre = s.top();
s.pop();
ans[pre] = i - pre;
}
s.push(i);
}
return ans;
}
};
```

### **...**

```
Expand Down
24 changes: 24 additions & 0 deletions solution/0700-0799/0739.Daily Temperatures/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ class Solution {
}
```

### **C++**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```cpp
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& T) {
int n = T.size();
vector<int> ans(n);
stack<int> s;
for(int i = 0; i < n; ++i) {
while(!s.empty() && T[s.top()] < T[i]) {
int pre = s.top();
s.pop();
ans[pre] = i - pre;
}
s.push(i);
}
return ans;
}
};
```

### **...**

```
Expand Down
20 changes: 20 additions & 0 deletions solution/0700-0799/0739.Daily Temperatures/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Author: Moriarty12138
*/
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& T) {
int n = T.size();
vector<int> ans(n);
stack<int> s;
for(int i = 0; i < n; ++i) {
while(!s.empty() && T[s.top()] < T[i]) {
int pre = s.top();
s.pop();
ans[pre] = i - pre;
}
s.push(i);
}
return ans;
}
};