algorithm
文章平均质量分 63
NewCoder_BL
new coder, keep moving
展开
-
907. Sum of Subarray Minimums
leetcode, 单调栈,monotonic stack, stack, array, 数组转载 2022-06-13 16:16:37 · 141 阅读 · 0 评论 -
200. Number of Islands
Given a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...原创 2019-02-01 17:56:31 · 389 阅读 · 0 评论 -
Graph representation and definition
representation:adjacency matrix好处是对边或者权重的queries 都是O(1), remove or add an edge也是O(1). 坏处是对点不友好,增加一个点的操作是O(V^2). 而且本身存储太space consuming,同样是点的平方复杂度。导致在sparse matrix里不适用。Adjacency Matrix is a 2D ar...原创 2019-01-28 08:33:22 · 267 阅读 · 0 评论 -
310. Minimum Height Trees
For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called min...原创 2019-01-31 17:37:14 · 124 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
这题是更general一些的二叉树serialization和deserialization,没有了BST里面的大小关系可以依赖,所以需要额外的存储,一种思路是生成两个序列,比如preorder和inorder,一种是存储NULL节点,是得我们可以按顺序或者按数量来以此恢复。因为NULL节点的大小普遍小于真实的node value,或者说存储更方便(任意指定符合即可),所以后者是我们主要使用的方法...原创 2019-01-07 10:43:06 · 114 阅读 · 0 评论 -
449. Serialize and Deserialize BST
经典题目之一,二叉树的遍历和深度广度优先都相关。一般的binary tree的serialization 和 deserialization 相对麻烦一点,因为没有多余特征可以利用。但binary search tree就有重要的大小关系可以利用。或者说,binary tree的恢复,往往需要preorder 和inorder两个序列,或者postorder和inorder。但是binary s...原创 2019-01-07 10:06:54 · 163 阅读 · 0 评论 -
DP intro: Rod cutting problem
Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. Fo...原创 2018-12-24 15:47:51 · 236 阅读 · 0 评论 -
Backtracking
需要注意的点:是否需要排序,一般有重复需要排序;isVisited 可以用来避免重复选择,比如permutationlastVisited可以用在有重复数字的时候避免结果重复不同题目区分点在于,递归中的结束条件,什么时候将tempres 放入res中,如何避免重复,每次选择的范围,选择的起始点。例题参考如下:Subsets : https://leetcode.com/proble...原创 2018-11-16 16:55:42 · 154 阅读 · 0 评论 -
Union-find and Disjoint Set Union
Disjoint Set Union (DSU) is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. A union-find algorithm is an algorithm that performs转载 2017-12-03 12:31:45 · 320 阅读 · 0 评论 -
690. Employee Importance
Problem:You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1 is the leader of em原创 2017-10-13 11:01:37 · 167 阅读 · 0 评论 -
快速排序的简洁写法
个人总结的两种快排写法原创 2016-06-18 22:19:02 · 741 阅读 · 1 评论 -
382. Linked List Random Node
链表随机返回值,如何在不知道长度的情况下随机抽样,水塘抽样原创 2016-09-14 12:47:19 · 218 阅读 · 0 评论 -
Morris Traversal-常量空间下遍历二叉树
morris traversal,常量空间复杂度下线性遍历二叉树原创 2016-09-02 10:02:08 · 482 阅读 · 0 评论 -
栈和队列在遍历二叉树中的使用
栈和队列在二叉树遍历的使用,非递归二叉树遍历原创 2016-08-31 12:52:13 · 3588 阅读 · 1 评论