上一页 1 2 3 4 5 6 ··· 8 下一页

2014年7月12日

LeetCode: Convert Sorted List to Binary Search Tree

摘要: 需要看一下。 阅读全文

posted @ 2014-07-12 11:31 longhorn 阅读(84) 评论(0) 推荐(0) 编辑

2014年5月20日

Diameter of a Binary Tree

摘要: www.geeksforgeeks.org/diameter-of-a-binary-tree/ 阅读全文

posted @ 2014-05-20 11:28 longhorn 阅读(116) 评论(0) 推荐(0) 编辑

2014年5月18日

LeetCode:Wildcard Matching

摘要: Implement wildcard pattern matching with support for'?'and'*'.DP:dp[i][j] = 1 表示s[1~i] 和 p[1~j] match。则:if p[j] == '*' && (dp[i][j-1] || dp[i-1][j])dp... 阅读全文

posted @ 2014-05-18 22:13 longhorn 阅读(128) 评论(0) 推荐(0) 编辑

2014年5月2日

Java Comparator

摘要: 1 Arrays.sort(points, new comparator());2 3 public static class comparator implements Comparator {4 public int compare(Point p1, Point p2) {5 ... 阅读全文

posted @ 2014-05-02 23:39 longhorn 阅读(159) 评论(0) 推荐(0) 编辑

2014年4月18日

LeetCode: Maximal Rectangle

摘要: Maximum size square sub-matrix with all 1shttp://www.geeksforgeeks.org/maximum-size-sub-matrix-with-all-1s-in-a-binary-matrix/ 1 public static int max... 阅读全文

posted @ 2014-04-18 11:39 longhorn 阅读(179) 评论(0) 推荐(0) 编辑

2014年4月16日

LeetCode: Substring with Concatenation of All Words

摘要: Longest Substring Without Repeating CharactersMinimum Window Substring 阅读全文

posted @ 2014-04-16 00:41 longhorn 阅读(97) 评论(0) 推荐(0) 编辑

2014年3月19日

Find the Kth largest Element in the Array

摘要: http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/可以用冒泡排序。外循环k次,不用n次。O(nk)。我想用quick sort的partition。每一次选择一个pivot,然后确定它的index。如果它的位置大于k,那么就在[left, index-1]找;如果它的位置小于k,那么就在[index+1, right]找。直到找到k。这里不能用和quick sort完全一样的partition,因为那个partition不会返回pivot的index。这里的做法是,先把pivot放到数组的末尾。然后对[ 阅读全文

posted @ 2014-03-19 03:40 longhorn 阅读(274) 评论(0) 推荐(0) 编辑

2014年3月18日

Lowest Common Ancestor of a Binary Tree

摘要: Given a binary tree, find the lowest common ancestor of two given nodes in the tree. 1 // This function returns pointer to LCA of two given values n1 and n2. 2 // This function assumes that n1 and n2 are present in Binary Tree 3 struct Node *findLCA(struct Node* root, int n1, int n2) 4 { 5 // Ba... 阅读全文

posted @ 2014-03-18 08:55 longhorn 阅读(172) 评论(0) 推荐(0) 编辑

Shuffle Array

摘要: 写一个shuffle数组的算法给一个数组A[],里面的数是无序的,比如 A[]={1,2,3,7,3,2,5}shuffle完之后,使之满足A[0]=A[2]= a[2] ...., 当i为n就结束了当i为0, 2, 4...,前i - 1个元素已经满足了。 如果a[ i ] > a[i + 1] 交换a[ i ] 和 a[i + 1], 这样使得前i个都满足。当i为1,3,5... 同理, 如果a[ i ] A[i+1]) {10 swap(A, i, i+1);11 }12 }13 ... 阅读全文

posted @ 2014-03-18 06:44 longhorn 阅读(429) 评论(0) 推荐(0) 编辑

Lowest Common Ancestor of a Binary Search Tree

摘要: Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the BST.4种情况。Both nodes are to the left of the tree.Both nodes are to the right of the tree.One node is on the left while the other is on the right.When the current node equals to either of the two nodes, this no 阅读全文

posted @ 2014-03-18 04:12 longhorn 阅读(144) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 8 下一页

导航