
Breadth-first Search
文章平均质量分 50
iteye_17352
这个作者很懒,什么都没留下…
展开
-
Leetcode - Word Ladder
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a timeEach i...原创 2015-06-23 10:01:16 · 106 阅读 · 0 评论 -
Leetcode - Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must e...原创 2015-06-26 09:19:26 · 129 阅读 · 0 评论 -
Leetcode - Number Of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...原创 2015-06-27 10:40:01 · 102 阅读 · 0 评论 -
Leetcode - Course Schedule
[url]https://leetcode.com/problems/course-schedule/[/url][分析] 典型的拓扑排序应用。先根据课程的先修关系构造一个graph,graph中的节点数==课程数,先修关系pair代表graph中的一条边,注意测试case中先修关系有重复,因此仅当创建新边时才更新相应节点的indegree。[code="java"]publi...原创 2015-06-27 11:49:29 · 120 阅读 · 0 评论 -
Leetcode - 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-06-29 21:59:29 · 127 阅读 · 0 评论 -
Leetcode - 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 ...原创 2015-06-29 22:03:45 · 92 阅读 · 0 评论 -
Leetcode - Majority Element II
[分析] Majority Element II这个扩展版可以沿用Majority Element 中的Moore Voting解法,大于 N / 3最多有两个,遍历过程中记录两个候选值。需注意的是,遍历结束后的候选值并不一定符合条件,比如input= [1,1,2],因此需要个检查过程。[ref] 对Moore Voting算法解析[url]http://blog.youkuaiyun.com/...原创 2015-06-30 22:12:59 · 335 阅读 · 0 评论