We can use bfs to solve this problem; By traverse the prerequisites array, we can generate two graph representations. One is an array of list of out n
分类:
其他好文 时间:
2016-02-23 08:24:58
阅读次数:
148
Using DFS to traverse the tree. 4 cases for each node in the tree: case 1: it's a leaf node, set a pointer pointing to the node. We're reaching an end
分类:
其他好文 时间:
2016-01-30 09:37:00
阅读次数:
204
Using DFS to traverse the node and build the a tree. for a node, it has following properties: If its a left child node of its parent, then the left bo
分类:
其他好文 时间:
2016-01-29 08:42:46
阅读次数:
168
Using DFS to traverse the BST, when we look through the BST to a certain node, this node must have the following property to make sure the tree is a v
分类:
其他好文 时间:
2016-01-28 13:45:06
阅读次数:
152
First we need to get the head node, use a boolean value to mark whether we find a new head or not. When we traverse the linked list,if(cur.val != cur....
分类:
其他好文 时间:
2016-01-24 08:09:34
阅读次数:
147
代码:public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { //int gap = nums.length; Map map = new HashMap...
分类:
其他好文 时间:
2016-01-12 07:44:44
阅读次数:
279
遍历数组找出有没有重复的元素 首先想到用一个数组记录出现的元素的个数代码:public class Solution { public boolean containsDuplicate(int[] nums) { if(nums.length == 0) return true...
分类:
其他好文 时间:
2016-01-12 06:36:34
阅读次数:
135
家庭作业3.70C版本代码long traverse(tree_ptr tp){long v = MAX;//7:$922337206854775807if(tp != NULL){lv = traverse(tp->left);rv = traverse(tp->right);v = lv v ?...
分类:
其他好文 时间:
2015-11-21 00:40:54
阅读次数:
256
家庭作业3.70(1)生成以上代码的C版本Long traverse(tree_ptrtp){Long v=MAX_LONG,rv,lv;If (tp!=NULL){lv=traverse(tp->left);rv=traverse(tp->right);v=lvtp->v?tp->v:v//Lin...
分类:
其他好文 时间:
2015-10-26 20:27:45
阅读次数:
105