Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1757d96

Browse files
Add Solution.java for 0739.Daily Temperatures
1 parent cd6a850 commit 1757d96

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Daily Temperatures
2+
3+
Given a list of daily temperatures **_T_**, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put **_0_** instead.
4+
5+
## Example :
6+
```
7+
Input: [73, 74, 75, 71, 69, 72, 76, 73]
8+
Output: [1, 1, 4, 2, 1, 1, 0, 0]
9+
```
10+
11+
**Note:** The length of **temperatures** will be in the range **[1, 30000]**. Each temperature will be an integer in the range **[30, 100]**.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[] dailyTemperatures(int[] T) {
3+
int[] res = Arrays.copyOf(T, T.length);
4+
for (int i = 0, length = T.length; i < length; i++) {
5+
int temp = T[i], j = i + 1;
6+
while (j < length && temp >= res[j]) {
7+
j ++;
8+
}
9+
res[i] = j == length ? 0 : j - i;
10+
}
11+
return res;
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /