随笔分类 -  Graph

摘要:参考:https://blog.csdn.net/u010365819/article/details/109367419 阅读全文
posted @ 2021-09-18 13:04 苗妙苗 阅读(41) 评论(0) 推荐(0)
摘要:There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] re 阅读全文
posted @ 2021-09-07 01:24 苗妙苗 阅读(64) 评论(0) 推荐(0)
摘要:You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell. You are given an m x 阅读全文
posted @ 2021-08-29 09:41 苗妙苗 阅读(140) 评论(0) 推荐(0)
摘要:There are n cities labeled from 1 to n. You are given the integer n and an array connections where connections[i] = [xi, yi, costi] indicates that the 阅读全文
posted @ 2021-08-29 01:45 苗妙苗 阅读(84) 评论(0) 推荐(0)
摘要:引用:https://bbs.csdn.net/topics/90443881 https://zhuanlan.zhihu.com/p/50085206 树是图的子集树有一个根节点,图没有 树是没有环的图(在图里面,环的路线是开始和结束都是一样的点)数可以递归遍历,图要看情况数有层次划分,图没有树 阅读全文
posted @ 2020-05-12 08:24 苗妙苗 阅读(1627) 评论(0) 推荐(1)
摘要:[抄题]: 求最多的联通的1的数量 Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizonta 阅读全文
posted @ 2018-03-11 21:25 苗妙苗 阅读(176) 评论(0) 推荐(0)
摘要:[抄题]: Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possibl 阅读全文
posted @ 2018-03-09 20:03 苗妙苗 阅读(810) 评论(0) 推荐(0)
摘要:[抄题]: 给出一个由小写字母组成的矩阵和一个字典。找出所有同时在字典和矩阵中出现的单词。一个单词可以从矩阵中的任意位置开始,可以向左/右/上/下四个相邻方向移动。 给出矩阵: 和字典: 返回 {"dog", "dad", "can", "again"} [暴力解法]: 时间分析: 空间分析: [思 阅读全文
posted @ 2018-02-26 08:49 苗妙苗 阅读(208) 评论(0) 推荐(0)
摘要:[抄题]: 给出 n 个节点,标号分别从 0 到 n - 1 并且给出一个 无向边的列表 (给出每条边的两个顶点), 写一个函数去判断这张`无向`图是否是一棵树。 给出n = 5 并且 edges = [[0, 1], [0, 2], [0, 3], [1, 4]], 返回 true. 给出n = 阅读全文
posted @ 2018-02-25 20:59 苗妙苗 阅读(352) 评论(0) 推荐(0)
摘要:[抄题]: 给一个01矩阵,求不同的岛屿的个数。 0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛。我们只考虑上下左右为相邻。 [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 找到一个岛,用dfs沉没一片岛。 [输入量]:空: 正常情况:特大:特小:程序里处理到 阅读全文
posted @ 2018-02-24 19:37 苗妙苗 阅读(349) 评论(0) 推荐(0)
摘要:[抄题]: 给出 n = 8 返回 [[2,2,2],[2,4]] // 8 = 2 x 2 x 2 = 2 x 4 [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 类似于全排列permutation, 用helper,忘了 [输入量]:空: 正常情况:特大:特小:程序里处 阅读全文
posted @ 2018-02-21 09:15 苗妙苗 阅读(239) 评论(0) 推荐(0)
摘要:[抄题]: Given a digit string excluded 01, return all possible letter combinations that the number could represent. A mapping of digit to letters (just l 阅读全文
posted @ 2018-02-20 16:02 苗妙苗 阅读(387) 评论(0) 推荐(0)
摘要:[抄题]: 您将获得一个使用这三个可能值初始化的 m×n 2D 网格。-1 - 墙壁或障碍物。 0 - 门。 INF - Infinity是一个空房间。我们使用值 2 ^ 31 - 1 = 2147483647 来表示INF,您可以假设到门的距离小于 2147483647。在代表每个空房间的网格中填 阅读全文
posted @ 2018-02-20 09:01 苗妙苗 阅读(165) 评论(0) 推荐(0)
摘要:[抄题]: 给一个二维的矩阵,包含 'X' 和 'O', 找到所有被 'X' 围绕的区域,并用 'X' 填充满。 样例 给出二维矩阵: X X X X X O O X X X O X X O X X 把被 'X' 围绕的区域填充之后变为: X X X X X X X X X X X X X O X 阅读全文
posted @ 2018-02-19 11:48 苗妙苗 阅读(232) 评论(0) 推荐(0)
摘要:找出最短路径 [抄题]: Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord 阅读全文
posted @ 2018-02-05 15:50 苗妙苗 阅读(222) 评论(0) 推荐(0)
摘要:不能重复: [抄题]: 给出一个候选数字的set(C)和目标数字(T),找到C中所有的组合,使找出的数字和为T。C中的数字可以无限制重复被选取。 例如,给出候选数组[2,3,6,7]和目标数字7,所求的解为: [7], [2,2,3] [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特 阅读全文
posted @ 2018-02-05 08:28 苗妙苗 阅读(290) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个字符串s,将s分割成一些子串,使每个子串都是回文串。 返回s所有可能的回文串分割方案。 给出 s = "aab",返回 [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: [二 阅读全文
posted @ 2018-02-04 18:02 苗妙苗 阅读(443) 评论(0) 推荐(0)
摘要:[抄题]: n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击。 给定一个整数n,返回所有不同的n皇后问题的解决方案。 每个解决方案包含一个明确的n皇后放置布局,其中“Q”和“.”分别表示一个女王和一个空位置。 对于4皇后问题存在两种解决的方案: [ [".Q..", // Sol 阅读全文
posted @ 2018-02-03 17:27 苗妙苗 阅读(400) 评论(0) 推荐(0)
摘要:无重复 [抄题]: Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1, 阅读全文
posted @ 2018-02-02 16:31 苗妙苗 阅读(428) 评论(0) 推荐(0)