随笔分类 - DFS
摘要:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l
阅读全文
摘要:题目链接: https://leetcode.com/problems/nested-list-weight-sum/ Given a nested list of integers, return the sum of all integers in the list weighted by th
阅读全文
摘要:input check, 正数? In every recursion, we at most try k groups, which means the search tree has k branches at most. And the depth of the search tree is
阅读全文
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w
阅读全文
摘要:Strobogrammatic Number II give us all the strings with length n, then we can call it to get strings with length between low.length() and high.length()
阅读全文
摘要:参考http://segmentfault.com/a/1190000003787462 找出所有的可能,必然是深度优先搜索。但是每轮搜索如何建立临时的字符串呢?因为数是“对称”的,我们插入一个字母就知道对应位置的另一个字母是什么,所以我们可以从中间插入来建立这个临时的字符串。这样每次从中间插入两个
阅读全文
摘要:How do we solve problem like this if we were given a normal tree? Yes, traverse it, keep a root to leaf running sum. If we see a leaf node (node.left
阅读全文
摘要:Better Solution: DFS, but only scan all the matches once! If a match can not make the 1st edge, then we do not discard it, we try 2nd, 3rd, 4th edge
阅读全文
摘要:DFS, my solution is to fill each edge of the square one by one. DFS to construct the 1st, then 2nd, then 3rd, then 4th. For each edge I scan all the m
阅读全文
摘要:Backtracking: time complexity O(N!) Use HashMap to store the initial debts of each person, negative means the person sends money to others, positive m
阅读全文
摘要:Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form
阅读全文
摘要:
阅读全文
摘要:Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algori
阅读全文
摘要:题目给了我们两个数组,一个是进程的数组,还有一个是进程数组中的每个进程的父进程组成的数组。题目中说结束了某一个进程,其所有的子进程都需要结束,由于一个进程可能有多个子进程,所以我们首先要理清父子进程的关系。所以我们使用一个哈希表,建立进程和其所有子进程之间的映射,然后我们首先把要结束的进程放入一个队
阅读全文
摘要:The idea is try to replace every "++" in the current string s to "--" and see if the opponent has the chance to win or not, if the opponent is guarant
阅读全文
摘要:类似200. Number of Islands, 但是lc考察的是题意的转化, 而不是光会个框架 考察: 对邻居的理解, 什么才是真正的邻居, 对邻居的遍历 UF 面试常考
阅读全文
摘要:带重复节点的subset
阅读全文
摘要:现在开始考bfs 了吗, 根据size办事,分情况了 dfs: 先序遍历 + 树的深度, 跟此题类似: 199 Binary Tree Right Side View
阅读全文
摘要:Given n unique integers, number k (1> kSumII(int[] A, int k, int target) { // write your code here ArrayList> ans = new ArrayList(); ArrayList list = new ArrayList(); ...
阅读全文
摘要:BFS 1. matrix 邻居都是找好的, 但是此题是八邻居问题 2. visited 数组是防止邻居重叠遍历的问题和重复加入的问题, 而此题需要遍历所有的邻居 但是此题再往队列加的时候判断是否为'E', 并且将其转化为'B' 3. and all of its adjacent unreveal
阅读全文

浙公网安备 33010602011771号