-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ44.js
37 lines (34 loc) · 1.15 KB
/
Q44.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 739. Daily Temperatures
// Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
var dailyTemperatures = function (temperatures) {
let answer = [];
let count = 0;
for (let i = 0; i < temperatures.length-1; i++) {
count = 0;
for (let j = i + 1; j < temperatures.length; j++) {
if (temperatures[i] < temperatures[j]) {
count++;
answer.push(count);
break;
}
if (temperatures[i] >= temperatures[j]) {
count++;
}
}
if(count >= temperatures.length-i-1) {
answer.push(0)
}
}
answer.push(0)
console.log(answer)
if (answer.length === temperatures.length) {
return answer;
}
else {
answer.pop()
return answer
}
};
// let temperatures = [73, 74, 75, 71, 69, 72, 76, 73];
let temperatures =[77,77,77,77,77,41,77,41,41,77]
console.log(dailyTemperatures(temperatures));