RDpWTeHM's LeetCode
个人 LeetCode 练习合集
FeatureOverload
github.com/RDpWTeHM
展开
-
【Leetcode】54. Spiral Matrix -- 我想到了逆时针动 matrix 而不动指针,我知道 zip 可以转置矩阵,但是我却没有写出 one-liner
我想到了逆时针动 matrix 而不动指针,我知道 zip 可以转置矩阵,但是我却没有写出 one-liner ????Overviewleetcode#54. Spiral MatrixOne-Liner简化逆时针旋转辅助函数递归简化one-linerReferenceleetcode#54. Spiral Matrix【描述】:Given a matrix of m x n elements (m rows, n columns), return all elements of the mat原创 2020-08-15 13:18:45 · 188 阅读 · 0 评论 -
【Leetcode】单调栈问题--739.DailyTemperatures;769.MaxChunksToMakeSorted;84.LargestRectangleinHistogram;85
Desc: n/aOverview单调栈《程序员代码面试指南》CH1-栈与队列 -- 单调栈结构Leetcode#739. Daily TemperaturesLeetcode#769. Max Chunks To Make SortedLeetcode#?. Max Chunks To Make Sorted IILeetcode#84. Largest Rectangle in HistogramLeetcode#85. Maximal Rectangle相关数据结构与算法Reference单调栈原创 2020-08-10 20:10:19 · 182 阅读 · 0 评论 -
【Leetcode】997. Find the Town Judge(找到小镇法官) - 社会名流问题
Desc: N/AOverview社会名流问题997. Find the Town JudgeReference社会名流问题接下来的这个例子是算法设计中的一个常见习题,这是一个不需要扫描所有数据(或者绝大部分)就能得到解答的很好例子。在n个人中,有一个被所有人知道但却不知道别人的人,这个人被定义为社会名流。现在的问题是如果存在,试找出社会名流。你可以使用的唯一方式是询问:“对不起,请问你知道某某人吗?”(假定所有回答都正确,甚至这位社会名流也将回答。)我们的目标是将问题的数目最小化。由于有 n(原创 2020-08-06 23:08:39 · 353 阅读 · 0 评论 -
【Leetcode】二进制解法题目整理(包括与、或、XOR逻辑运算) - 更新中
Overview注:草稿,题目细节内容待更新。1342. Number of Steps to Reduce a Number to Zero1356. Sort Integers by The Number of 1 Bits1374. Generate a String With Characters That Have Odd Counts注:草稿,题目细节内容待更新。1342. Number of Steps to Reduce a Number to Zero2020/07/22Giv原创 2020-07-27 14:38:38 · 533 阅读 · 0 评论 -
【Leetcode】可以一行(One-Liner)Python代码解决的 Leetcode 问题 - 掌握 Python 高阶函数
Overview高阶函数reduce1281. Subtract the Product and Sum of Digits of an Integerreduce 的典型用法自己实现 `sum` 功能的函数使用匿名函数 lambda 实现阶乘 N!N!N!1486. XOR Operation in an Array反转字符串sorted1356. Sort Integers by The Number of 1 Bitsall844. Backspace String Compareany - N/Af原创 2020-07-23 10:59:47 · 367 阅读 · 0 评论 -
【Leetcode】二叉树问题整理笔记 之 遍历取值变体问题
Overview二叉树定义897. Increasing Order Search Tree - 增序二叉搜索树二叉树定义# Definition for a binary tree node.class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right897. Inc原创 2020-07-12 15:31:29 · 184 阅读 · 0 评论 -
【Leetcode】二叉树问题整理笔记 之 普通遍历取值
Overview遍历二叉树257. Binary Tree Paths - 输出二叉树所有根到叶的路径94. Binary Tree Inorder Traversal -- 中序遍历144. Binary Tree Preorder Traversal -- 前序遍历538. Convert BST to Greater Tree - 中序遍历变体问题965. Univalued Binary ...原创 2019-07-18 17:04:28 · 186 阅读 · 0 评论 -
【Leetcode】字符串问题整理笔记
Overview383. Ransom Note387. First Unique Character in a String451. Sort Characters By FrequencyReference383. Ransom NoteSolution:class Solution: def canConstruct(self, ransomNote: str, maga...原创 2019-07-14 14:12:39 · 323 阅读 · 0 评论 -
【Leetcode】数组问题整理笔记
Overview283. Move ZeroesReference283. Move ZeroesSolution:class Solution: def get_zero_count(self, nums): ret = 0 for i in nums: if i == 0: ret +=...原创 2019-07-13 15:42:25 · 231 阅读 · 0 评论 -
【Leetcode】二叉树问题整理笔记
Overview按层遍历算法问题简单的队列实现101. Symmetric Tree104. Maximum Depth of Binary Tree按层遍历算法问题简单的队列实现class DQ: def __init__(self, val): self._dq = [val] def pop_left(self): return s...原创 2019-07-11 16:44:00 · 243 阅读 · 0 评论 -
【Leetcode】链表问题整理笔记
Overview83. Remove Duplicates from Sorted List82. Remove Duplicates from Sorted List IIReference83. Remove Duplicates from Sorted ListSolution:# Definition for singly-linked list.# class ListNo...原创 2019-07-11 11:06:29 · 287 阅读 · 0 评论 -
【Leetcode】Fibonacci 问题整理笔记
Overview70. Climbing StairsN/AReference70. Climbing StairsSolution:不算很简单,也不算很明显。先将一阶,二阶,三阶,四阶,… 一个个爬阶方法写出,然后推出来。1+2 => 33+5 => 8猜测。可不可以使用增强归纳假设解决这个问题呢。实现:from functools import lru...原创 2019-07-11 09:29:11 · 109 阅读 · 0 评论 -
【Leetcode】二分法方案问题整理:平方根等
Overview69. Sqrt(x)69. Sqrt(x)Solution:class Solution: def mySqrt(self, x: int) -> int: s = 0 e = 1 m = 0 found = 0 while True: prod = ...原创 2019-07-10 15:37:23 · 206 阅读 · 0 评论 -
【Leetcode】数值运算
Overview66. Plus One(大数加一)67. Add Binary(二进制加)66. Plus One(大数加一)Solution:class Solution: def plusOne(self, digits: List[int]) -> List[int]: ret = digits[:] _len = len(ret...原创 2019-07-10 14:25:55 · 158 阅读 · 0 评论 -
【Leetcode】15. 3Sum
OverviewQuestionSolutionQuestionSolution讨论区的 solution O(n2n^2n2)class Solution(): def threeSum(self, nums): def twoSum(nums, i, total): #res_set = set() res...原创 2019-06-13 14:12:03 · 65 阅读 · 0 评论 -
【Leetcode】49. Group Anagrams 笔记
OverviewQSolution总结昨晚做了 49. 这一题,实际上这题没有什么特别的想法。参考 Solution 实现的。不过思路是很值得了解,学习的。所以写成博客稍微记录一下。QSolution可以分组的字符串必然满足排序后相等如:e, a, ta, t, e,t, e, a排序之后比较就是相等的。排序后作为元组用作字典的键,索引未加入的字符串(排序然后...原创 2019-06-11 12:27:28 · 103 阅读 · 0 评论 -
【LeetCode】46. Permutations - 归纳法解决排列问题
Overview问题描述思路Solution问题描述思路[3] --> [[3]][1, 2] || .pop() \/ 2, 1[ /--> [1, 2], [2], - \--> [2, 1],][1, 2, 3] || .pop() \/ 3, 2, ...原创 2019-05-29 20:47:02 · 113 阅读 · 0 评论 -
【LeetCode】使用栈一次性解决 19. Remove Nth Node From End of List 问题
19. Remove Nth Node From End of List原解决代码模板根据 LeetCode 提供的 `ListNode` 实现自己动手实现一个用于 debugSolution简单栈功能实现代码一些特殊情况先了解一下正常的测试用例示范:`n` 和 `listnode` 都是 1使用栈解决方案的最终提交代码运行结果其它特殊输入了解空 `ListNode` 输入`n` 超过 `lis...原创 2019-04-27 16:40:42 · 202 阅读 · 0 评论 -
【LeetCode】使用递归方案解决 17. Letter Combinations of a Phone Number,再记忆体化递归
17. Letter Combinations of a Phone Number分析草稿草稿实现(递归算法)注:细节上略有错误,逻辑/算法原理上没有问题递归算法最终实现class Solution: def letterCombinations(self, digits): mapping = {1: '*', 2: 'abc', 3: 'def', ...原创 2019-04-27 14:08:45 · 211 阅读 · 0 评论 -
【LeetCode】排序解决 4. Longest Common Prefix 问题
先排序再解决,思路和方案还是很直观的:class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if len(strs) > 1: ret = sorted(strs) mini = ret[0] max...原创 2019-04-26 16:29:32 · 162 阅读 · 0 评论 -
【LeetCode】Palindrome Number - 使用双向队列(deque) 解决“回文数”问题
使用双向队列(deque) 解决“回文数” 使用双向队列(deque) 解决“回文数”简要版(隐式使用deque ‘方法’)完全 deque 版deque 使用 python 列表实现。简要版(隐式使用deque ‘方法’)class Solution: def isPalindrome(self, x: 'int') -> 'bool': src = str...原创 2019-04-22 00:38:33 · 305 阅读 · 0 评论 -
【LeetCode】myatoi
实现 myatoiclass Solution: def myAtoi(self, str: 'str') -> 'int': INT_MIN = -2**31 INT_MAX = 2**31-1 import re rule = r"^[\s]*([-|+]?[\d]+)" sret = re.fin...原创 2019-04-20 17:11:18 · 198 阅读 · 0 评论