摘要: We know that the longest path problem for general case belongs to the NP-hard category, so there is no known polynomial time solution for it. However, for a special case which is directed acyclic graph, we can solve this problem in linear time.First, take a look at an algorithm that sloves the short 阅读全文
posted @ 2014-04-12 07:20 门对夕阳 阅读(332) 评论(0) 推荐(0) 编辑
摘要: We all know that the shortest path problem has optimal substructure. The reasoning is like below:Supppose we have a path p from node u to v, another node t lies on path p: u->t->v ("->" means a path).We claim that u->t is also a shortest path from u to t, and t->v is a short 阅读全文
posted @ 2014-04-12 06:45 门对夕阳 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Problem:此题的做法和 “检查单链表回文” 那道题的骨架是一样的,用 Recursive 的方法,简洁而优雅。参考回文那道题:http://www.cnblogs.com/Antech/p/3847752.htmlCode in Java:public class Solution { ... 阅读全文
posted @ 2014-04-12 03:08 门对夕阳 阅读(356) 评论(0) 推荐(0) 编辑
摘要: This is a simple but important algorithm when dealing with singly linked list.This algorithms can reversely access a singly linked list using O(n) time. Below is my code in Java.class Node{ Node next; int val;}class SinglyLinkedList{ Node head; Node tail; //append a new Node t... 阅读全文
posted @ 2014-04-11 05:28 门对夕阳 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Problem statement:Thought: Since TreeNode has a self-recursive structure, it's very natural and easy to come up with a recursive implement. But the tricky part is how to implement this using a iterative method. The three binary tree traversal methods: pre-order, in-order and post-order can all b 阅读全文
posted @ 2014-04-10 04:41 门对夕阳 阅读(939) 评论(0) 推荐(0) 编辑
摘要: Binary Tree的三种Traversal方法老是记混,故于此总结下。Preorder: Node -> Left subtree -> Right subtreeInorder: Left subtree -> Node -> Right subtreePostorder: Left subtree -> Right subtree -> NodePre, In, Post指的是Node本身在[Node, Left, Right]中被访问的顺序。Pre is 1st, In is 2nd, Post is 3rd.Note: Inorder trave 阅读全文
posted @ 2014-04-10 03:08 门对夕阳 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Problem:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key 阅读全文
posted @ 2014-04-10 02:58 门对夕阳 阅读(353) 评论(0) 推荐(0) 编辑
摘要: 匹配html的<a>标签:<a[^>]+>.*?</a>匹配html的<img>标签中的src属性:(?<=<img[^>]+src=")\S+?(?=") 阅读全文
posted @ 2013-04-25 14:11 门对夕阳 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 在这里,有必要把Attribute和Property这两个词仔细地辨别一下。这两个词的混淆由来已久。混淆的主要原因就是大多数中文译本里既把Attribute译为“属性”,也把Property译为“属性”。其实,这两个词所表达的不是一个层面上的东西。Property 属于面向对象理论范畴。在使用面向对象思想编程的时候,我们常常需要对客观事物进行抽象,再把抽象出来的结果封装成类,类中用来表示事物状态的成员就是 Property。比如我要写一个模拟赛车的游戏,那么必不可少的就是对现实汽车的抽象。现实中的汽车身上会带有很多数据,但在游戏中我可能只关心它的长 度、宽度、高度、重量、速度等有限的几个数据, 阅读全文
posted @ 2013-04-20 21:02 门对夕阳 阅读(256) 评论(0) 推荐(0) 编辑
摘要: Fudannlp:开源中文自然语言处理工具包|中文分词|词性标注|依存句法分析|指代消解。支持JAVA调用,和WebServices调用。ictclas:中科院研发的一个分词系统,支持的编程语言较丰富。 阅读全文
posted @ 2013-04-19 23:10 门对夕阳 阅读(224) 评论(0) 推荐(0) 编辑