《DATA STRUCTRUES A Psuedocode Approach with C++》Chaper 3. Linked List Learn Note

3-1 LINEAR LIST CONCEPTLinear lists can be divided into two categories: general and restricted.In a general list, data can be inserted and deleted anywhere and there are no restrictions on the operations that can be used to process the list. Such as the random list, ordered list.In a restricted list, data can only be added or deleted at the ends of the structure and processing is restricted to op... Read More

小旭讲解 LeetCode 399. Evaluate Division 并查集

原题英文 —— Evaluate DivisioEquations are given in the formatA / B = k, whereAandBare variables represented as strings, andkis a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return-1.0.Example:Givena / b = 2.0, b / c = 3.0.queries are:a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .return[6.0, 0.5, -1.0, 1.0, -1.0 ].The input is:vec... Read More

小旭讲解 LeetCode 39. Combination Sum 回溯法

原题Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesamerepeated number may be chosen fromcandidatesunlimited number of times.NoteAll numbers (includingtarget) will be positive integers.The solution set must not contain duplicate combinations.Example 1Input: candidates... Read More


如果一个问题具有最优子结构的性质,此外子问题具有重叠性质,那么可以采用自底向上的动态规划的思路进行求解。同时,往往可以用递归的方式自顶向地进行求解,即分治法。如果用分治法去求解这个问题时,能够利用备忘录法进行避免对于子问题的重复计算,那么其计算的效率可以和动态规划的计算效率相比。文章来源:胡小旭 =>动态规划与分治法的思考 Read More


共同的递归性质在广义上来说,所有递归的算法都属于分治法。无非是将问题分解成一个规模更小的问题,还是将问题分解成若干个,甚至和输入规模多项式级别的子问题。那么对于前者,有些作者称作是减治法,后者称作分治法。那么对于回溯法(以深度优先搜搜方式进行)来说,目前为止我见过的都是通过递归的形式来实现的,那么从这个意义上来讲,回溯算法就是分治法的一种。回溯状态的有无再说,之所以称作是回溯法,是因为在搜索的过程中需要回溯到问题的某个状态,所以这往往需要保存回溯时的一些状态属性。然而,分治法通常并不需要考虑回溯状态的保存。分解问题的规模分治法往往是将问题分解成若干个子问题的形式,然而回溯法往往是将问题分解成规模更小的一个子问题。由于分治法将问题分解成若干个子问题,故当前问题的解需要依赖于若干个子问题,也就是若干个搜索路径的解,所以重点在于如何合并子问题的解;而然回溯法问题规模就为1个,当前的搜索路径的问题... Read More


从2018年7月份开始,基础薄弱的我从0开始刷LeetCode题目。目的性很明确,也很简单——就是为了提高解决问题的思考实践能力,也为了提升自己的核心竞争力。也许,牛人会觉得这并不算什么竞争力。是的,我同意的。但,这是我目前能做的比较基础的事情罢了。迄今(2018年12月28日)为止,已经刷了108道题目。顺序基本上是按照出现的频率(Frequency)来刷的,这个频率在LeetCode上需要订阅后才可以看得到。那么在刷了108道题目后,有那么一些题目会觉得“似曾相识”了,也会有一种触类旁通的感觉了。所以,我觉得应该适当放慢刷题的速度,同时做做总结了。所以,计划了一项视频解说计划,在YouTubeh和B站都建立了《小旭解说算法之路》的频道,欢迎订阅,多多提建议。那么,进入正题。经过了108道题的历练之后,我来说说对于分治法、回溯法和动态规划的理解。我觉得他们三者是一个相互有交集的概念,并不... Read More

[LeetCode]743. Network Delay Time

原题There are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from source to target.Now, we send a signal from a certain node K. How long will it take for all nodes to receive the signal? If it is impossible, return -1.NoteN will be in the ... Read More

[LeetCode]893. Groups of Special-Equivalent Strings

原题You are given an array A of strings.Two strings S and T are special-equivalent if after any number of moves, S == T.A move consists of choosing two indices i and j with i % 2 == j % 2, and swapping S[i] with S[j].Now, a group of special-equivalent strings from A is a non-empty subset S of A such that any string not in S is not special-equivalent with any string in S.Return the number of groups o... Read More

[LeetCode]Valid Palindrome II

原题Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1Input: "aba"Output: TruExample 2Input: "abca"Output: TruExplanation: You could delete the character 'c'.NoteThe string will only contain lowercase characters a-z. The maximum length of the string is 50000.思路水题。判断是否是回文字符串最简单的方式就是从左右两端逐步向中心逼近(双指针),如下代码[code lang="cpp"for (in... Read More


Ford-Fulkerson算法(亦即标号法?)的输入与步骤如下输入给定一个容量为c的图G=(V, E),源点s与汇点(终点)步骤对图G中每一个边(u, v)的流量f(u, v)进行初始化为查询过程:寻找(DFS、深度优先搜索方式)图G中的一条路径p,其中每一条边(u, v) ∈p,都有fc(u, v) = c(u, v) - f(u, v) > 0(c(u, v) 代表当前边的容量,f(u, v) 代表当前边已有的流量,即c(u, v) - f(u, v)代表当前边可用的最大流量,即剩余流量调整过程:计算当前路径下每条边的最小剩余容量,cf(p) = min{fc(u, v) : (u, v) ∈p},然后对于每条边进行如下操作f(u, v) = f(u, v) + cf(p) (前向狐f(v, u) = f(v, u) - cf(p) (后向狐往复上述2与3步骤,直至无法找到路径p为止... Read More

[LeetCode]Sum of Subarray Minimums

原题Given an array of integers A, find the sum of min(B), where B ranges over every (contiguous) subarray of A.Since the answer may be large, return the answer modulo 10^9 + 7.Example 1Input: [3,1,2,4Output: 1Explanation: Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4].Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.  Sum is 17.Note1 <= A.length <1 <= A[i] <... Read More

[LeetCode]Fruit Into Baskets

原题In a row of trees, the i-th tree produces fruit with type tree[i].You start at any tree of your choice, then repeatedly perform the following stepsAdd one piece of fruit from this tree to your baskets.  If you cannot, stop.Move to the next tree to the right of the current tree.  If there is no tree to the right, stop.Note that you do not have any choice after the initial choice of starting tree... Read More

[LeetCode]Remove Nth Node From End of List

原题Given a linked list, remove the n-th node from the end of list and return its head.ExampleGiven linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->5.NoteGiven n will always be valid.Follow upCould you do this in one pass思路首先,明确题意。题目给出了一个只有后继(successor),没有前驱(predecessor)的一个单向链表。要求删除倒数第n个节点。那么,思路自然会想到的就是在一次遍历就搞定题目要求。所以,我们自然要在遍历的过程中保存一... Read More


原题Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.NoteThe solution set must not contain duplicate quadruplets.ExampleGiven array nums = [1, 0, -1, 0, -2, 2], and target = 0.A solution set is[-1, 0, 0, 1][-2, -1, 1, 2][-2, 0, 0, 2题解本题的... Read More

[LeetCode]3Sum Closest

原题Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.ExampleGiven array nums = [-1, 2, 1, -4], and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).思路本题目的解题思路和3Sum很像,区别在于3Sum求解的是三个数字和为target(即为0),然而3Su... Read More


原题Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplicate triplets.For example, given array S = [-1, 0, 1, 2, -1, -4]A solution set is[-1, 0, 1][-1, -1, 2题解暴力解法因为需要计算三个数字的总和,所以需要进行3层的遍历,故时间复杂度需要O(n^3),看来不可取,果断放弃。毕竟是medium难度的题,不至于这么个解法。two-pointes solutio... Read More

[LeetCode]Two Sum

原题Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.ExampleGiven nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].题解暴力解法暴力解法使用两层for循环,遍历每一种存在的情况。[code lang="cpp"class Solution publicvector<int... Read More

[LeetCode]Palinkdrom Number

ProbleDetermine whether an integer is a palindrome. Do this without extra space.Some hints[code lang="shell" collapse="true"Could negative integers be palindromes? (ie, -1If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that th... Read More

[LeetCode]Roman to Integer

ProbleGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.IdeaFinding the Law of Changing Roman Numbers into Arabic Numbers。Solutio[code lang="cpp"class Solution publicint romanToInt(string s) int l = s.length(), a = 0;for (int i = 0; i < l; ++iif (i < l - 1 && char2int(s[i]) < char2int(s[i + 1])) a -= char2int(s[i]);} else a += char2int(s[i]);... Read More


YoukYouTub相关资源到底该如何刷LeetCode: https://qoogle.top/how-to-brush-leetcode/ [视频] 如何找实习:https://tinyurl.com/y8fzjzaf[视频] 如何刷题:https://tinyurl.com/yazujcb3[视频] 如何社交:https://tinyurl.com/yavh53qb[视频] 一对一职场资讯:https://tinyurl.com/yb6pfwo视频来源:https://www.youtube.com/watch?v=Z3KrtEaw0v Read More

2018LeeCode算法题解一之Valid Palindrome

原题Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.NoteHave you consider that the string might be empty? This is a good question to ask during an interview.For the purpose of this problem, we define empty string as valid palindrome.原题链接:https://... Read More


一、方向选择都说选择比努力重要,这个鸡汤我觉得可以干了。起初接触人工智能领域是在硕士选择导师的时候,当时民叔推荐来到人工智能与机器人研究所,跟随现在的硕导做图像处理方面的研究,用到一些机器学习的算法做分类工作。在学校学习平台比较重要,它决定了你会见识什么人、什么样的黑科技、什么样的应用等,没有这些东西勾起你的好奇心,也就没有对未来的规划或者说期待。硕士期间,养成了看论文的习惯,专注领域顶级期刊论文,当然了首先是先把自己研究的课题相关知识看的透彻,这个在第二小节中会介绍:为什么硕士课题很重要。一些我认识是牛人的人说,看论文是在跟领域大牛在交流,这个确实刚开始体会不到,起初很排斥看论文,更加上我的英语那是一个...后来看多了,发现知识之间都是相通的,可能解决一个问题用的是同一个方法,这样看一篇论文的时间会大大缩短,有效率了,心里便更愿意去看论文。康奈尔大学图书馆网站每天更新世界上各个大牛写的论... Read More


之前看到一篇文章《八年phper的高级工程师面试之路》,然后最近我也在面试,面了有百度、360、滴滴、小米、微博、58赶集、搜狗、瓜子二手车等公司,最后也进了心仪的公司,面试过程中学到了很多东西,所以也想和大家分享一下,虽然我的工作经验才3年左右。 注:下面题目的答案只是我思考和查询资料的结果,并不代表完全准确,有错误的地方大家可以指正,有更好的方案可以提出,大家一起讨论。算法1.反转函数的实现[code lang="php"/** 反转数组* @param array $ar* @return arra*function reverse($arr$n = count($arr);$left = 0;$right = $n - 1;while ($left < $right$temp = $arr[$left];$arr[$left++] = $arr[$right];... Read More

ZigZag Conversion(math)

QuestioThe string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibilityP A H A P L S I I Y I And then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string and make this conversion given a number of rowsstring convert(string text, int nRows);convert("PAYPAL... Read More


正题Reverse digits of an integer.Example1: x = 123, return 32Example2: x = -123, return -32思考改题为简单难度(水题),根据题意可以依次取到给定的整型数x的最高位到最低的数,然后依次将其乘10的x次幂后进行累加即可得到结果。这里,要知道32位的整型一共有九个0,故声明i=1000000000;代码[code lang="cpp"class Solution publicint reverse(int x) long int i = 1000000000, rev_i = 1, r = 0, start = 0;while (x != 0) int c = x / i;if (start == 0 && c != 0) start = 1;if (start == 0 && i /= 10;... Read More


LeetCode正题Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.ExampleInput: "babad"Output: "bab"Note: "aba" is also a valid answer.ExampleInput: "cbbd"Output: "bb"思考回文字符串即正向顺序和反向顺序的字幕排序是一致的字段串。题的大意为寻找一个指定字符串中的最长的回文字符串。首选,暴力解法需要遍历所有子串并判断子串是否为回文字符串。假设给定字符串长度n,那么子串的总数为​n(n+1)/2(即1 2 3 ... n的和),即需要O(n^2),然后判断每个子串是否为回文字符串的时间复杂度为O(n),即总共需要... Read More