
LeetCode
文章平均质量分 89
xutiantian1412
考虑到历史的行程,我就从地质专业润了去做风控算法。
展开
-
9.5.1 拓扑排序及LeetCode题目 —— Course Schedule II & Minimum Height Trees
首先解释AOV网的概念:用一个有向无环图DAG表示一项工程或项目,我们用顶点表示活动,用弧\边表示活动之间的优先关系。这样的图称为顶点表示活动的网即AOV网(Active on Vertex Network)。再看一下拓扑排序topologicalSort对于任何有向图而言,其拓扑排序为其所有结点的一个线性排序(对于同一个有向图而言可能存在多个这样的结点排序)。该排序满足这样的条件——对于图中的任意两个结点u和v,若存在一条有向边从u指向v,则在拓扑排序中u一定出现在v前面。拓扑排序主要用来原创 2021-02-17 19:42:20 · 363 阅读 · 3 评论 -
9.2.3 图的遍历及路径 —— Reconstruct Itinerary & All Paths From Source to Target
前面的遍历都没有关注路径本身,本节从两道题目着手,穴习一个图的遍历及路径。首先了解几个概念。1.欧拉通路:通过图(有向图或者无向图)中的所有边,且每条边只通过一次且行遍所有顶点的通路。2.欧拉回路:当欧拉通路为回路时,称为欧拉回路。3.欧拉图:具有欧拉回路的无向图。半欧拉图:具有欧拉通路但不具有欧拉回路的无向图。简单来说,类似于[一笔画]问题。七桥问题是最早涉及这一问题的数学趣闻,有兴趣的可以了解一下https://www.cnblogs.com/graytido/p/10421927.h.原创 2021-02-10 10:35:15 · 565 阅读 · 0 评论 -
9.2.2 图的遍历LeetCode题目 —— Find the Town Judge & Clone Graph & Keys and Rooms
133.Clone GraphGiven a reference of a node in aconnectedundirected graph.Return adeep copy(clone) of the graph.Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.题解:注意题目的入参和出参,都是Node结构,而题目说明及例子多少绕了个弯。...原创 2021-02-09 17:39:44 · 285 阅读 · 0 评论 -
10.6 贪心算法详解及LeetCode题目
可参考几篇博客详解贪心算法(Python实现贪心算法典型例题)五大常用算法之一:贪心算法算法概述贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,所做出的是在某种意义上的局部最优解。贪心算法不是对所有问题都能得到整体最优解,关键是贪心策略的选择,选择的贪心策略必须具备无后效性,即某个状态以前的过程不会影响以后的...原创 2020-04-06 22:03:32 · 783 阅读 · 0 评论 -
10.5.2 (python) 动态规划字符串类LeetCode题目 —— Interleaving String & Distinct Subsequences
下面我们看两道字符串子序列的问题 subsequence,首先明白子序列是不必连续的。97.Interleaving StringGivens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 ...原创 2020-03-29 18:19:54 · 300 阅读 · 0 评论 -
10.5.1 (python) 动态规划字符串类LeetCode题目 —— Edit Distance & Regular Expression Matching
下面学习几道字符串的题目,难度一般较大,但是也有共性,有套路,必须掌握几道经典的题目。72.Edit DistanceGiven two wordsword1andword2, find the minimum number of operations required to convertword1toword2.You have the following 3 ...原创 2020-03-29 14:17:34 · 339 阅读 · 0 评论 -
LeetCode刷题指南——题目精选3
7. 二叉树遍历树的概念,树的存储结构,孩子兄弟存储方式二叉树、完全二叉树的性质深度优先、广度优先遍历即先序中序后序层次遍历的递归和非递归写法(相当于6道题)101. Symmetric Tree111. Minimum Depth of Binary Tree103. Binary Tree Zigzag Level Order Traversal105. Const...原创 2020-03-22 00:15:38 · 401 阅读 · 0 评论 -
10.4.3 (python) 动态规划专题之股票买卖 —— Best Time to Buy and Sell Stock
这一系列涉及到LeetCode中几道关于股票stock买卖时机的题目,给出一数组,代表每天股票的价格,我们要按要求,计算你所能获取的最大利润。需要注意的是,你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。Say you have an array for which theithelement is the price of a given stock on dayi.De...原创 2020-03-15 11:27:32 · 669 阅读 · 0 评论 -
python数据结构与算法学习路线及系列文章汇总(持续更新。。)
虽然是用python搞机器学习的大项目,还是要从零开始学习数据结构那一套理论。不知不觉数据结构及算法系列的学习及LeetCode刷题已经一大堆,现对此汇总。如下是一套比较合理的完整的学习路径:1)数据结构与算法的理论,包括复杂度的思想,从线性表开始(链表,栈和队列),然后是数组和字符串的初级理论和题目(双指针);查找算法中深刻理解二分查找及哈希查找。2)接下来打算学习树及二叉树相关姿势...原创 2018-10-02 22:29:10 · 12222 阅读 · 12 评论 -
10.4.2 (python) 动态规划专题之换零钱 —— Coin Change & Perfect Squares
换零钱是一个典型的动态规划场景。322.Coin ChangeYou are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up t...原创 2020-03-08 20:24:20 · 309 阅读 · 0 评论 -
10.4.1 (python) 动态规划专题之最长递增子序列 —— Longest Increasing Subsequence & Russian Doll Envelopes
Longest Increasing Subsequence 简称 LIS,是一个经典问题。我们看一下经典解题方法及一道应用题目。300.Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Exam...原创 2020-03-08 19:50:40 · 901 阅读 · 0 评论 -
10.3.3 (python) 动态规划数组类LeetCode题目 —— Dungeon Game & Frog Jump
来看两道 hard 级别的题目,其子问题性质很明显,就是动态规划,难点就是我们可能找不好子问题的关系式。174.Dungeon GameThe demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M ...原创 2020-03-08 00:06:35 · 304 阅读 · 0 评论 -
10.3.2 (python) 动态规划数组类LeetCode题目 —— Decode Ways & Range Sum Query 2D
这几道题稍微加大难度,DP的框架是不变的,关键是分析问题的结构,分析状态转移关系。91.Decode WaysA message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26...原创 2020-03-07 20:11:45 · 317 阅读 · 0 评论 -
10.3.1 (python) 动态规划数组类LeetCode题目 —— Minimum Path Sum & Triangle & Maximum Product Subarray
这一节的几篇,都是解析动态规划数组类题目,相对于后面的字符串类问题来说,还是比较容易的。首先来看比较几个简单的DP题目,巩固一下前面所学套路。64.Minimum Path SumGiven amxngrid filled with non-negative numbers, find a path from top left to bottom right whichmi...原创 2020-02-27 21:49:47 · 340 阅读 · 0 评论 -
10.2 动态规划算法套路及空间优化 —— Climbing Stairs & Unique Paths
这一篇文章从最简单的动态规划题目开始,结合上一节动态规划三要素,阐述DP问题的基本套路解法。原创 2020-02-26 22:30:44 · 609 阅读 · 0 评论 -
LeetCode刷题指南——题目精选2
这是LeetCode经典题目总结文章~第二篇4. 二分查找熟练掌握二分查找的通用格式,包括递归及非递归的写法;33. Search in Rotated Sorted Array34. Find First and Last Position of Element in Sorted Array5. 排序排序算法的分类,每种方法的时空复杂度,最好、最坏复杂度,稳定性及...原创 2020-03-21 23:33:25 · 574 阅读 · 0 评论 -
LeetCode刷题指南——题目精选1
这是LeetCode经典题目总结文章~基础:将数据结构及算法学习的差不多,LeetCode题目按类别刷题及总结,参考鄙人数据结构及算法系列文章~按类别将每类题目做好,大概刷250道左右的程度即可。再按照如下精选题目进行知识点巩固,文章总结了各种类型的经典题目,用于第二遍刷题。第二遍刷题同时还可以做一些第一遍时没做的题目,争取刷到400道,但是题目在于精细而不在于数量,一般面试就考察基础...原创 2020-02-01 23:11:41 · 988 阅读 · 0 评论 -
3.1.1 python数组双指针算法1——求和问题(LeetCode 2sum & 3sum & 4sum)
LeetCode题目中数组和字符串的占比很大。在Array(数组)和String(字符串)的题目中,很多都是用双指针去解决问题的。在此综合几道Array中双指针的题目将这一思想方法汇总学习。后续还会有双指针在其他方面的应用。双指针算法介绍在之前链表的题目中也有双指针这一思想,详情可看 python数据结构之链表——带环链表及交叉链表(双指针法),链表中的双指针与数组中不同。双指针遍历数组时...原创 2018-04-20 16:12:54 · 4143 阅读 · 5 评论 -
7.6.2 (python)AVL LeetCode题目 及 AVL结点插入操作详解
这一节关于 AVL 平衡二叉搜索树的题目,刷了不少题,关于平衡树的题目确实很少,做来做去,就先看下面这两道小儿科的题目吧。110.Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree i...原创 2019-08-11 10:05:55 · 1111 阅读 · 0 评论 -
7.3.3 树和二叉树LeetCode题目解析(3)
二叉树这一数据结构十分重要,在此不断补充一些有趣味的题目,不断学习。623.Add One Row to TreeGiven the root of a binary tree, then value vand depth d, you need to add a row of nodes with value vat the given depth d. The root n...原创 2019-07-31 19:06:26 · 137 阅读 · 0 评论 -
7.10.2 (python)堆的应用及Leetcode题目解析
我们简单看几道二叉堆/优先队列的应用。215.Kth Largest Element in an ArrayFind thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element....原创 2019-08-21 23:58:55 · 342 阅读 · 0 评论 -
8.2.1 (python)排序算法之链表排序LeetCode题目(1) —— Sort List & Merge k Sorted Lists
首先,在排序的题目中,我们先总结、学习一下,链表排序的问题,顺便也回忆一下链表相关操作。对应于下面两道题147.Insertion Sort ListSort a linked list using insertion sort.148.Sort ListSort a linked list inO(nlogn) time using constant space com...原创 2019-09-03 23:27:05 · 360 阅读 · 0 评论 -
8.2.2 (python)排序算法及LeetCode题目(2) —— Insert Interval & Contains Duplicate III & Wiggle Sort II
这一节是数组排序的相关题目,并没有直接应用算法解决问题那么好的事情。这一部分都是难度较高的题目,重点是解题思路,和排序相关,反而没用到什么排序算法。57.Insert IntervalGiven a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary)...原创 2019-09-05 09:37:43 · 235 阅读 · 0 评论 -
8.2.3 python排序LeetCode题目(3) —— K Pairs with Smallest Sums & Kth Smallest Element in a Sorted Matrix
这一节再看一些排序相关的题目。373.Find K Pairs with Smallest SumsYou are given two integer arraysnums1andnums2sorted in ascending order and an integerk.Define a pair(u,v)which consists of one elemen...原创 2019-09-05 20:47:26 · 277 阅读 · 0 评论 -
7.6.3 (python)BST LeetCode题目 —— Delete Node in a BST & Recover Binary Search Tree
这一节再解析两道题,略有难度的。450.Delete Node in a BSTGiven a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST...原创 2019-08-09 17:46:17 · 284 阅读 · 0 评论 -
7.6.1 (python)BST LeetCode题目 —— Minimum Absolute Difference in BST & Convert BST to Greater Tree
BST相关题目并不多,毕竟是一个查找的数据结构。对于BST的题目,最常用的就是中序遍历获得递增序列,进而解决一些题目。在做这一部分题目之前,先默念中序遍历大法。以98.Validate Binary Search Tree 为例,如何判断是否为二叉搜索树呢,就是对树进行中序遍历,判断序列是否递增。class Solution: def isValidBST(self, roo...原创 2019-08-05 09:38:58 · 298 阅读 · 0 评论 -
7.4.2 python二叉树路径问题及LeetCode题目解析(2)
下面题目中的路径,定义有所延伸,在解法思路及时间空间复杂度上有所挑战。437.Path Sum IIIYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does no...原创 2019-07-28 21:32:23 · 401 阅读 · 0 评论 -
4.2.1 LeetCode字符串类题目选做(1) —— Roman to Integer & Text Justification
字符串的题目,首先是一些简单的字符串处理的问题,不涉及到什么算法。关键点是找规律,思考全面所有的情况。13 Roman to IntegerRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Given a roman numeral, convert it to an in...原创 2018-10-06 13:55:41 · 409 阅读 · 0 评论 -
3.2.2 LeetCode数组类题目选做(2)—— Spiral Matrix & Rotate Image & Set Matrix Zeroes
Array 类题目选做之二 二维矩阵54. Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7,...原创 2018-09-12 20:28:06 · 287 阅读 · 0 评论 -
3.2.1 LeetCode数组类题目选做(1)—— First Missing Positive & Majority Element & Product of Array Except Self
数组题目概述数组的题目很多很重要,一般和其他知识点综合应用。包括Two pointer,Binary Search,Dynamic Programming,Greedy,Backtracking 等,各类算法都将分别选做一些题目学习交流总结。这一系列选择出一些非应用上述知识点,而是一些奇思妙想的、套路很深的数组的题目,总结后扩展思路,领悟一些可能会再次遇见的套路,也许可以处理类似的问题。...原创 2018-08-26 23:34:48 · 379 阅读 · 0 评论 -
3.1.3 python数组双指针算法3——滑动窗口(LeetCode Subarray Product Less Than K & Container With Most Water)
双指针算法的第三篇,题目的类型与前面都不同,鄙人给这个思想起了个不太合适的名字——滑动窗,其实与第一种两数求和的思想差不多,不同点大概是,滑动窗强调的是双指针之间的数组,求和问题只是一头一尾的遍历操作,关注的是双指针所在位置的元素,包括元素交换一类的也是关注的是指针所在位置的元素。因此用窗口一词形容我们的观察对象是双指针之间的所有元素。应用场景之滑动窗口713.Subarray Prod...原创 2018-08-13 00:07:17 · 911 阅读 · 1 评论 -
3.1.2 python数组双指针算法2——元素交换(LeetCode Remove Duplicates from Sorted Array & Remove Element)
距上一篇双指针的算法介绍已有四个月,换了个忙碌的工作,没时间也没心情刷题了。然而学习是一种信仰,一口气把two pointer剩下的一些题目学习了一下,现在继续总结归纳two pointer问题。上一节是几个经典的求和问题,这一节是元素交换的几个典型场景。应用场景之元素交换26. Remove Duplicates from Sorted ArrayGiven a sorted a...原创 2018-08-11 09:52:07 · 613 阅读 · 0 评论 -
2.2.3 python数据结构之栈——应用(3)Leetcode题目解析
接触了前面这么多题目后,我们应该对栈的思想有了深刻理解并提高了应用栈去解决问题、设计算法的能力,下面再看最后两道LeetCode的题目。第一题仍然是函数调用栈的应用,鄙人在学习了之前的题目后,终于可以亲自敲出来一道题目了,难度不大。第二道题是数组的问题,利用栈优化了算法,相信这一思路对其他问题也会有所启发。636. Exclusive Time of Functions(函数的专有...原创 2018-04-18 12:54:31 · 662 阅读 · 0 评论 -
2.2.2 python数据结构之栈——应用(2)中缀表达式计算与函数调用栈
前面一部分学习的是括号匹配和后缀表达式的计算,后缀表达式是没有括号的,每遇到一个运算符就弹出两个元素计算。那么如果遇到含有括号/各种优先级的中缀表达式,如何运算呢?当然还是离不开栈的应用啦。Leetcode 224. Basic Calculator (基础计算器)Implement a basic calculator to evaluate a simple expressio...原创 2018-04-17 17:26:13 · 759 阅读 · 0 评论 -
1.5 python数据结构之链表——带环链表及交叉链表(双指针法)
这一篇是LeetCode上关于链表的两道题目,属于做过就会,没做过难死的那种。都不是常规的单链表,一个是两个单链表交叉,一个是带环链表,均用到双指针的办法解决。1)160.Intersection of Two Linked Lists 两链表交叉Write a program to find the node at which the intersection of two singly...原创 2018-03-27 18:05:48 · 1045 阅读 · 0 评论 -
1.3 python数据结构之链表——链表右移/链表分割/链表逆序
都是一些LeetCode上关于链表的题目,多刷一些这样的题目有助于我们全面熟悉链表那一套理论方法。题目1. 61. Rotate List (将链表右移K个位置)Given a list, rotate the list to the right by k places, where k is non-negative.Example:Given 1->2->3->...原创 2018-03-20 14:59:00 · 1298 阅读 · 3 评论 -
4.2.3 LeetCode字符串类题目选做(3) —— String to Integer (atoi) & Integer to English Words
这一节是关于字符串和数字的解析的两个题目,往往要求我们不要用内置的类型转换函数。8. String to Integer (atoi)Implement atoi which converts a string to an integer.具体要求简述:字符串开始可以有多个空格,然后是可能有的+/-号以及多个数字,如" -42",解析为对应的数字。注意的是:数字后,可以有其他字符,...原创 2018-10-13 12:02:42 · 266 阅读 · 0 评论 -
4.2.2 LeetCode字符串类题目选做(2)—— Length of Last Word & Reverse Words in a String
这一节也是对字符串的一些简单处理,而且都是处理word,难度都不大,做一做这类题有点像NLP工程师。58. Length of Last WordGiven a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in t...原创 2018-10-07 22:28:01 · 278 阅读 · 0 评论 -
7.4.1 python二叉树路径问题及LeetCode题目解析(1)
二叉树从根结点到每个叶子结点都形成一条路径,当然,从任意节点到任意节点也是一条路径,这一类题目较多是我们二叉树问题的重点,也伴随着一些有难度的题目。递归遍历依次访问树中结点可以构成路径,另外前面提到后序遍历非递归写法的栈中保留当前元素的所有祖先结点。首先我们看最简单的一道题,所有路径输出:257.Binary Tree PathsGiven a binary tree, retu...原创 2019-06-02 21:16:38 · 291 阅读 · 0 评论 -
7.3.1 二叉树遍历的应用及LeetCode题目解析(1)
这一节,我们看一下应用二叉树的遍历,可以解决哪些问题,如何应用这些原理刷题。花式遍历,加上我们接下来解析的题目,可以基本涵盖数据结构二叉树这部分的主要内容了。还是要对其中难点好好练习。其实,在LeetCode中有几道题目就是遍历二叉树, 如94 Binary Tree Inorder Traversal 144 Binary Tree Preorde...原创 2019-05-05 00:06:13 · 738 阅读 · 0 评论