摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree. For example: Given the below binary tree,1/ \2 3Ret... 阅读全文
posted @ 2014-12-24 07:19 来自海边的一片云 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Thursday, October 23, 2014CodingTMD’s Reading ListFollowing reading list is selected from the papers I had read in the past 3 years. It will help you ... 阅读全文
posted @ 2014-12-20 04:16 来自海边的一片云 阅读(172) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#include using namespace std;static vector alpha;void seq_printer(unsigned int* a, unsigned int* a_end){ for (unsigned int* i = a; i n) { // we want only necklaces, not pre-necklaces or Lyndon words if (n % p == 0) { seq_printer(a + 1, a + p + 1); ... 阅读全文
posted @ 2014-02-19 00:15 来自海边的一片云 阅读(661) 评论(0) 推荐(0) 编辑
摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot",&q 阅读全文
posted @ 2014-02-17 04:50 来自海边的一片云 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 1.经典的N皇后问题就是个经典的DFS算法我摆到第一行第一列了哦,然后就开始Deep看下一行,可以放哪,然后递推,直到棋盘的行列到。 void NQueenHelper(vector> & board, vector>& result, int row) { int N = board.size(); if (row == N)//reached end scenario { string str; vector final; for (int i = 0; i>& board,... 阅读全文
posted @ 2014-02-16 14:26 来自海边的一片云 阅读(621) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens="catsanddog",dict=["cat", "cats", "and", "sand", "dog"].A 阅读全文
posted @ 2014-02-16 13:55 来自海边的一片云 阅读(404) 评论(0) 推荐(0) 编辑
摘要: 问题,read()从stream中读出一个字符。然后在stream 中找到含有目标字符串的位置。这个题目是个典型的KMP算法。KMP算法的关键在于如果build Next数组讲KMP算法讲的比较好的网站http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html其实用平实的逻辑思考也能想明白这个算法究竟是怎么来。string S1 abcd......string S2 Ai.....An1. 当拿S2和S1去匹配的时候,当在S2的第K位置发生不匹配的时候,最最naive的方法就 阅读全文
posted @ 2014-02-15 13:36 来自海边的一片云 阅读(332) 评论(0) 推荐(0) 编辑
摘要: place holder 阅读全文
posted @ 2014-02-12 04:01 来自海边的一片云 阅读(88) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].排列问题,直观的排列问题如{1,2,3} 当第一次位的1 确定的时候后,需要从2,3 里面进行全排列,然后得到 1,2,3 和,1,3,2。因此得到一个算法,用一个flags 来记录这个数是否已经被用过。如果已经选到第n个字符( level ==n) 那 阅读全文
posted @ 2014-02-10 05:42 来自海边的一片云 阅读(320) 评论(0) 推荐(0) 编辑
摘要: Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors./** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */图的遍历有两种方法,一种是广度优先搜索,一种是深度优先搜索。最naive的方法就是遍... 阅读全文
posted @ 2014-02-10 03:35 来自海边的一片云 阅读(164) 评论(0) 推荐(0) 编辑