05 2013 档案

摘要:要知道单源最短路径的的两种算法--bellman-ford算法以及dijkstra算法之前,首先我们要来了解一种技术:松弛技术。所谓的松弛技术,实际上用一串代码即可解释: RELAX(u,v,w) if d(v)> d(u) + w(v,u) then d(v) <---- d(u)+w(v,u) pai(v)<----u这就是所谓的松弛一条边(u,v)的过程。意思就是:我们想要找到v的最短路径,那么我们这时候已经知道了到u的最短路径,那么利用u的最短路径+(u,v)的长度, 看这个长度是否比当前v上标明的,到v的最短路径还要短。如果是的话,就把最短的值给d(v),v的父.. 阅读全文
posted @ 2013-05-10 15:11 kamendula 阅读(160) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.这道题貌似在陈利人的微博上看到过,当时是有思路的:即采用hash的方法。但是再 阅读全文
posted @ 2013-05-05 20:42 kamendula 阅读(222) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path 1->2 represents the num 阅读全文
posted @ 2013-05-03 21:52 kamendula 阅读(179) 评论(0) 推荐(0)
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X 阅读全文
posted @ 2013-05-03 21:19 kamendula 阅读(143) 评论(0) 推荐(0)
摘要:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab", Return [ ["aa","b"], ["a","a","b"] ]不太清楚。网上说是用dfs来做,但是可能因为自己水平不够,不明白如何算是 阅读全文
posted @ 2013-05-03 20:45 kamendula 阅读(190) 评论(0) 推荐(0)