Skip to content

Commit 16d8302

Browse files
committedDec 3, 2017
[N-0] add 739
1 parent 1d42165 commit 16d8302

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Your ideas/fixes/algorithms are more than welcome!
2222

2323
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
2424
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
25+
|739|[Daily Temperatures](https://leetcode.com/problems/daily-temperatures/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_739.java) | O(n^2) | O(1) | Medium|
2526
|737|[Sentence Similarity II](https://leetcode.com/problems/sentence-similarity-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_737.java) | O(nlogk + k) n is the length of max(words1, words2), k is the length of pairs| O(k) | Medium| Union Find
2627
|735|[Asteroid Collision](https://leetcode.com/problems/asteroid-collision/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_735.java) | O(n) | O(n) | Medium | Stack
2728
|734|[Sentence Similarity](https://leetcode.com/problems/sentence-similarity/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_734.java) | O(n*k) | O(1) | Easy | HashTable
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 739. Daily Temperatures
5+
*
6+
* Given a list of daily temperatures, produce a list that,
7+
* for each day in the input, tells you how many days you would have to wait until a warmer temperature.
8+
* If there is no future day for which this is possible, put 0 instead.
9+
* For example, given the list temperatures = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].
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].
12+
*/
13+
public class _739 {
14+
15+
public static class Solution1 {
16+
public int[] dailyTemperatures(int[] temperatures) {
17+
if (temperatures == null || temperatures.length == 0) {
18+
return temperatures;
19+
}
20+
int[] result = new int[temperatures.length];
21+
for (int i = 0; i < temperatures.length; i++) {
22+
for (int j = i + 1; j < temperatures.length; j++) {
23+
if (temperatures[j] > temperatures[i]) {
24+
result[i] = j - i;
25+
break;
26+
}
27+
}
28+
}
29+
return result;
30+
}
31+
}
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._739;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertArrayEquals;
8+
9+
public class _739Test {
10+
private static _739.Solution1 solution1;
11+
private static int[] temperatures;
12+
private static int[] expected;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _739.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
temperatures = new int[]{73, 74, 75, 71, 69, 72, 76, 73};
22+
expected = new int[]{1, 1, 4, 2, 1, 1, 0, 0};
23+
assertArrayEquals(expected, solution1.dailyTemperatures(temperatures));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.