
BFS
文章平均质量分 77
ljffdream
这个作者很懒,什么都没留下…
展开
-
【Leetcode】Find the kth in the BST
[题目] [思路] BST的特点就是排序性,左边的节点一定比root小,右边的节点一定比root大。 另外就是二分性。 找第k个,可以先看左边树节点的个数,小于k的话,就保证了肯定是在右边。那么去找右边的k-left. k - left,就变成了新的k. 数root所在的树的节点数。这个就是用递归实现。想法就是,如果root自己本身就是null,那么就return 0; 否则至转载 2015-07-08 21:28:09 · 525 阅读 · 0 评论 -
[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 ti转载 2015-07-06 09:12:15 · 480 阅读 · 0 评论 -
[Leetcode]Number of Island
[题目] 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 ma转载 2015-07-07 09:55:24 · 289 阅读 · 0 评论