首页 > TAG信息列表 > Letecode

【golang必备算法】 Letecode 146. LRU 缓存机制

力扣链接:146. LRU 缓存机制 思路:哈希表 + 双向链表 为什么必须要用双向链表? 因为我们需要删除操作。删除一个节点不光要得到该节点本身的指针,也需要操作其前驱节点的指针,而双向链表才能支持直接查找前驱,保证操作的时间复杂度 O(1)。 为什么要在链表中同时存储 key 和 val,而不是

【golang必备算法】单调队列 Letecode 239. 滑动窗口最大值

单调队列 今天刷力扣,碰到一道关于单调队列的题,总结一下 239. 滑动窗口最大值 单调队列思想: 队列没有必要维护窗口里的所有元素,只需要维护有可能成为窗口里最大值的元素就可以了,同时保证队列里的元素数值是由大到小的。 单调队列不是单纯的给队列中元素排序,那和优先级队列没有什么

【golang必备算法】动态规划 Letecode 516.最长回文子序列

516.最长回文子序列 题目 思路 回文子序列都是动态规划经典题目,用从Carl哥那里学来的动态规划五部曲: 确定dp数组以及下标的含义确定递推公式dp数组如何初始化确定遍历顺序列举推导dp数组 确定dp数组以及下标的含义 dp[i] [j]:字符串s在[i, j]范围内最长的回文子序列的长度为

【golang必备算法】动态规划 Letecode 516.最长回文子序列

516.最长回文子序列 题目 思路 回文子序列都是动态规划经典题目,用从Carl哥那里学来的动态规划五部曲: 确定dp数组以及下标的含义 确定递推公式 dp数组如何初始化 确定遍历顺序 列举推导dp数组 确定dp数组以及下标的含义 dp[i] [j]:字符串s在[i, j]范围内最长的回文子序列的长度

letecode编程学习(29)

题目 数组的每个索引作为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost[i](索引从0开始)。 每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯。 您需要找到达到楼层顶部的最低花费。在开始时,你可以选择从索引为 0 或 1 的元

letecode 编程学习(19)

题目 给定一个字符串S,检查是否能重新排布其中的字母,使得两相邻的字符不同。 若可行,输出任意可行的结果。若不可行,返回空字符串。 示例 1: 输入: S = "aab" 输出: "aba" 示例 2: 输入: S = "aaab" 输出: "" 注意: S 只包含小写字母并且长度在[1, 500]区间内。 解题思路 为了保证

letecode编程学习(15)

题目 在二维空间中有许多球形的气球。对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。由于它是水平的,所以纵坐标并不重要,因此只要知道开始和结束的横坐标就足够了。开始坐标总是小于结束坐标。 一支弓箭可以沿着 x 轴从不同点完全垂直地射出。在坐标 x 处射出一

letecode [237] - Delete Node in a Linked List

 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], which looks like following:   Example 1: Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You

letecode [] -

 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3Ou

letecode [167] - Two Sum II - Input array is sorted

 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must

letecode [111] - Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7],   

letecode [83] -

Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2Output: 1->2 Example 2: Input: 1->1->2->3->3Output: 1->2->3 题目大意:   给定排序链表,删除其中重复的元素。   理  解 :   遍历链表,cur指向当前