作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 倒序遍历 栈 日期 题目地址:https://leetcode.com/problems/daily-temperatures/description/ 题目描述 Given a list of daily temperatures, produce a list that, for each day in the input, tells you how m…
原题链接在这里:https://leetcode.com/problems/daily-temperatures/description/ 题目: Given a list of daily temperatures, produce a list 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 fu…
题目大意 给你接下来每一天的气温,求出对于每一天的气温,下一次出现比它高气温的日期距现在要等多少天 解题思路 利用单调栈,维护一个单调递减的栈 将每一天的下标i入栈,维护一个温度递减的下标 若下一个温度p,比栈顶元素对应的温度p'要高,就出栈,且p就是p'的最近的“高温” 代码实现 from collections import deque class Solution: def dailyTemperatures(self, temperatures): ans = [0]*len(tempe…
题目标签:HashMap 题目给了我们一组温度,让我们找出 对于每一天,要等多少天,气温会变暖.返回一组等待的天数. 可以从最后一天的温度遍历起,从末端遍历到开头,对于每一天的温度,把它在T里面的index存入 temp[101] 保存.然后对于每一天的温度,从温度+1 到100 全部遍历后,找出变暖温度里离当天最近的那一天.存入answer.具体看code. Java Solution: Runtime: 8 ms, faster than 91.33% Memory Usage: 42.7…
[LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址https://leetcode.com/problems/triangle/description/ 题目描述: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjac…
Question 739. Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: public int[] dailyTemperatures(int[] temperatures) { int[] ans = new int[temperatures.length]; for (int i = 0; i<temperatures.length; i++) { int highId…
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积累可以对以后在对算法中优化带来好处.Ok,今天是我做的第一题Add Two Sum. 题目要求 Given an array of integers, find two numbers such that they add up to a specific target number. The fu…
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1]. [解析] 题意:求一个数组的全排列.与[LeetCode]Permutations 解题报告 不同的是…
[LeetCode]Island Perimeter 解题报告 [LeetCode] https://leetcode.com/problems/island-perimeter/ Total Accepted: 16143 Total Submissions: 28552 Difficulty: Easy Question You are given a map in form of a two-dimensional integer grid where 1 represents land…
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/description 题目描述: Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example:…