graph
文章平均质量分 83
yuanhisn
这个作者很懒,什么都没留下…
展开
-
LeetCode 210 - Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a p...原创 2015-05-26 14:09:27 · 54 阅读 · 0 评论 -
Zenefits Interview - Javascript library dependency
写一个程序, 把package dependency的关系找出來, 面试官是用javascript当例子, 解释题目给我听, 基本上就是用topological sort去解如下 package dependency // HTML <script src='foo.js'></script> // code for foo.js require('bar...原创 2015-05-08 12:16:34 · 54 阅读 · 0 评论 -
Find if there is a path between two vertices in a directed graph
Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second. For example, in the following graph, there is a path from vertex 1 to 3. As anothe...原创 2015-05-02 23:00:02 · 112 阅读 · 0 评论 -
Zenefits Interview - Determine If a Graph is a valid Binary Tree
INPUT: (A,B) (A,C) (B,G) (C,H) (E,F) (B,D) (C,E) OUTPUT: (A(B(D)(G))(C(E(F))(H))) (parent(child)(child)) Error Code Type of error E1 More than 2 children E2 ...原创 2015-05-02 13:46:15 · 67 阅读 · 0 评论 -
LeetCode 133 - Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each ...原创 2015-03-20 01:10:44 · 48 阅读 · 0 评论 -
Google Interview - 警察到房间的最短距离
一个 n x n 矩阵,每个房间可能是封闭的房间,可能是警察,可能是开的房间, 封闭的房间不能过,返回一个n x n矩阵,每一个元素是最近的警察到这个房间的最短距离。 初始矩阵中-1代表封闭房间,INT_MAX代表普通房间,0代表有警察的房间。 Solution: 把警察都找出来,然后一起push到BFS的queue里面,同时搜索。复杂度可降为O(n^2)。 Starting fro...原创 2015-08-01 12:58:22 · 59 阅读 · 0 评论