随笔分类 - 数据结构与算法
data structure, algorithm
摘要:这里有个问题,父进程退出了,子进程还没退出。解决方案是在RunChild中调用: 可以查看下man 2 prctl。 https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits
阅读全文
摘要:https://coolshell.cn/articles/8239.html 主要讲的是《Implementing Lock-Free Queues》的论点,具体直接看论文最好。这里总结些要点。 CAS就是Compare And Swap。gcc可以调用: 这段代码讲出无锁的两个关键手段: 一个就
阅读全文
摘要:实际上,每次更新需要最小的n-1个值去更新。假设总共更新k次。 那么,最终的情况,所有数的和等于(min+k) * n,min是初始数据的最小值,n是数组的长度; 更新k次,每次更新n-1个值,那么就有 sum+(n-1)*k = (min+k)*n; 化简一下,k=sum-min*n
阅读全文
摘要:Given a binary tree, a target node in the binary tree, and an integer value k, print all the nodes that are at distance k from the given target node. ...
阅读全文
摘要:Given inorder and level-order traversals of a Binary Tree, construct the Binary Tree. Following is an example to illustrate the problem.BinaryTreeInpu...
阅读全文
摘要:Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node.自己想的复杂了,其实就是一个反向的inorder。新的值就是前面所有元素的...
阅读全文
摘要:Given a very large n-ary tree. Where the root node has some information which it wants to pass to all of its children down to the leaves with the cons...
阅读全文
摘要:Given a binary tree, print it vertically. The following example illustrates vertical order traversal. 1 / \ 2 3 / \ / \ 4 5 6 7 \ \ 8 9The output of p...
阅读全文
摘要:Given a string and a positive integer d. Some characters may be repeated in the given string. Rearrange characters of the given string such that the s...
阅读全文
摘要:A suffix array is a sorted array of all suffixes of a given string. The definition is similar to Suffix Tree which is compressed trie of all suffixes ...
阅读全文
摘要:In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eul...
阅读全文
摘要:8.2Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocate...
阅读全文
摘要:Implement pow(x, n).快速求幂,注意n是负数的情况。 1 class Solution { 2 public: 3 double pow(double x, int n) { 4 double ans = 1.0; 5 int symbol ...
阅读全文
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total numb...
阅读全文
摘要:Given API: int Read4096(char* buf); It reads data from a file and records the position so that the next time when it is called it read the next 4k cha...
阅读全文
摘要:匈牙利算法,求二分图最大匹配。若P是图G中一条连通两个未匹配顶点的路径,并且属于M的边和不属于M的边(即已匹配和待匹配的边)在P上交替出现,则称P为相对于M的一条增广路径。(M为一个匹配)由增广路的定义可以推出下述三个结论:P的路径长度必定为奇数,第一条边和最后一条边都不属于M。所以Line 25-...
阅读全文
摘要:Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MBProblemCarol is a great alchemist.In her world, each metal has a name of 2N (N is an int...
阅读全文
摘要:在线求第k个数做得多了,在线求中位数也是用堆,一个最大堆,一个最小堆。思想大概是这样子的:一个最大堆,一个最小堆,最大堆对应于前n/(n+1)个数,最小堆对应于后n/n+1个数;假设最大堆堆项元素为n1, 最小堆堆顶为n2, 则n1 s2, 那么:如果m >= n1, m插入到最小堆,s2=s2+...
阅读全文
摘要:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below a...
阅读全文
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did y...
阅读全文

浙公网安备 33010602011771号