摘要: 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 来自海边的一片云 阅读(318) 评论(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) 编辑