自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

原创 [LeetCode题解] 面试题22. 链表中倒数第k个节点

前言:4月实在是太忙了,忙到几乎抽不出时间做题,也有工作级和专业级的编程都考过了的原因,5月做题继续,正好部门也有编码大赛。目前想法,把剑指offer刷完。题目链接: https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/.利用快慢指针,快指针先走K个元素,然后快慢指针一起往下走。走到头,慢...

2020-05-07 15:28:24 207

原创 [LeetCode题解] 84. 柱状图中最大的矩形

题目链接: https://leetcode-cn.com/problems/largest-rectangle-in-histogram/.本题目的直观思路是什么?遍历每一根柱子,由于组成矩形的高已知,我们向左右两边延伸,求矩形的最大长度。这种解法的时间复杂度为O(n^2)。单调栈做法:此做法借鉴Leetcode官方解答。其具体思路如下:维护一个单调递增的栈。遍历每一根柱子,当其高...

2020-03-21 20:30:19 200

原创 [LeetCode题解] 300. 最长上升子序列

题目链接: https://leetcode-cn.com/problems/longest-increasing-subsequence/.在Youtube,B站上搜了以下,关于O(nlogn)解法没有找到一讲我秒懂的tutorial,因此详细记录一下LIS 时间复杂度为O(nlogn)的做法。解法1:DP,通过双层遍历,如果num[i] > num[j],dp[i] = max(dp...

2020-03-14 22:54:55 350

原创 [LeetCode题解] 322. 零钱兑换

题目链接: https://leetcode-cn.com/problems/coin-change/.提供两种思路:解法一. DP执行用时 : 892 ms, 在所有 Python 提交中击败了77.35%的用户内存消耗 :12.1 MB, 在所有 Python 提交中击败了33.04%的用户class Solution(object): def coinChange(self...

2020-03-09 09:09:43 220

原创 [LeetCode题解] 994. 腐烂的橘子

题目链接: https://leetcode-cn.com/problems/rotting-oranges/.第一次做的时候,通过遍历grid来统计每一次好橘子的个数,由值为2的节点开始向外感染。如果好橘子的个数在t1和t2时间内一样,代表好橘子无法被遍历到,return -1。由于这种方法需要不断地遍历整个grid(统计好橘子数量),所以时间上损耗较大。class Solution(ob...

2020-03-04 19:41:49 176

原创 [LeetCode题解] 739. 每日温度

题目链接: https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/submissions/.该题的基本思路是维护一个单调栈。class Solution: def dailyTemperatures(self, T: List[int]) -> List[int]: ...

2020-03-01 15:35:40 169

原创 [LeetCode题解] 160. 相交链表

题目链接: https://leetcode-cn.com/problems/intersection-of-two-linked-lists/solution/xiang-jiao-lian-biao-by-leetcode/.解题思路:双指针法同时遍历A, B两个链表,当遍历完成时候,A的指针指向B,B的指针指向A,继续遍历。双指针在交点相遇。a(特有部分) + 公共部分 + b(特有...

2020-02-15 11:02:21 113

原创 [LeetCode题解] 3. 无重复字符的最长子串

题目链接: https://leetcode-cn.com/problems/number-of-closed-islands/submissions/.这道题的思路与200.岛屿数量https://leetcode-cn.com/problems/number-of-islands/是一致的,都是通过DFS对于岛屿进行“感染”。class Solution(object): def ...

2020-01-24 16:39:32 251

原创 [LeetCode题解] 139. 单词拆分

题目链接: https://leetcode-cn.com/problems/word-break/.利用dp思想,以tmp_string = "watchdog"为例,如果tmp_string[:5] – watch 和 tmp_string[5:] --"dog"均在dict中,那么tmp_string必然可以被dict分解。class Solution(object): def ...

2020-01-20 20:01:59 201

原创 [LeetCode题解] 394. 字符串解码

题目链接: https://leetcode-cn.com/problems/decode-string/.这道题是我在公司模拟自测的时候遇到的一道题。参照题解区大佬的思路:由于括号内嵌套括号,与栈的先进后出一致。class Solution(object): def decodeString(self, s): """ :type s: str ...

2020-01-20 19:50:57 182

原创 [LeetCode题解] 102. 二叉树的层次遍历

题目链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal/comments/.自己的版本:class Solution(object): def levelOrder(self, root): """ :type root: TreeNode :rty...

2020-01-04 22:11:01 167

原创 [LeetCode题解] 199. 二叉树的右视图

题目链接: https://leetcode-cn.com/problems/increasing-order-search-tree/comments/.class Solution(object): def increasingBST(self, root): """ :type root: TreeNode :rtype: TreeN...

2020-01-04 21:38:55 165

原创 [LeetCode题解] 980. 不同路径 III

题目链接: https://leetcode-cn.com/problems/unique-paths-iii/comments/.第一次自己写的代码版本class Solution(object): def uniquePathsIII(self, grid): """ :type grid: List[List[int]] :rtyp...

2020-01-04 21:22:11 137

原创 [LeetCode题解] 921. 使括号有效的最少添加

题目链接: https://leetcode-cn.com/problems/minimum-add-to-make-parentheses-valid/.第一次自己写的代码class Solution(object): def minAddToMakeValid(self, S): """ :type S: str :rtype: in...

2020-01-03 15:31:22 245

原创 [LeetCode题解] 145. 二叉树的后序遍历

题目链接: https://leetcode-cn.com/problems/binary-tree-postorder-traversal/.后序遍历原则:先遍历左子树,再遍历右子树,最后遍历根节点。递归版本:class Solution(object): def postorderTraversal(self, root): """ :type ...

2020-01-03 14:38:31 265

原创 [LeetCode题解] 111. 二叉树的最小深度

题目链接: https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/.第一次自己写的代码class Solution(object): min_depth = 2000 #理解为极大值即可 def minDepth(self, root): """ :type root: Tre...

2020-01-03 14:22:15 148

原创 [LeetCode题解] 107. 二叉树的层次遍历 II

题目链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/.这道题与No.1302类似,都关注了树的层序遍历。class Solution(object): def levelOrderBottom(self, root): """ :type root: Tr...

2020-01-02 22:35:03 113

原创 [LeetCode题解] 1302.层数最深叶子节点的和

[LeetCode题解] 1302.层数最深叶子节点的和题目:https://leetcode-cn.com/problems/deepest-leaves-sum/这道题很明显是对于树的层序遍历。解法一:class Solution(object): def deepestLeavesSum(self, root): """ :type root: Tr...

2020-01-02 21:26:42 267

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除