题解 | #每日温度#
每日温度
https://www.nowcoder.com/practice/1f54e163e6944cc7b8759cc09e9c78d8
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ public List<int> temperatures (List<int> dailyTemperatures) { // write code here if (dailyTemperatures == null || dailyTemperatures.Count == 0) return null; if (dailyTemperatures.Count == 1) return new List<int>() { 0 }; List<int> lsN = new List<int>(); for (int i = 0; i < dailyTemperatures.Count; i++) { lsN.Add(0); for (int j = i + 1; j < dailyTemperatures.Count; j++) { if (dailyTemperatures[j] - dailyTemperatures[i] <= 0) continue; lsN[i] = j - i; break; } } return lsN; } }