摘要: 回溯法 vector > solveNQueens(int n) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; vector queens; vector cols(n,false); vector diag(2*n,false); vector ardiag(2*n,false); dfs(0,n,queens,co... 阅读全文
posted @ 2013-10-19 16:54 summer_zhou 阅读(138) 评论(0) 推荐(0) 编辑
摘要: vector anagrams(vector &strs) { // Note: The Solution object is instantiated only once and is reused by each test case. unordered_map> mmap; vector res; for(vector::iterator it = strs.begin();it!=strs.end();it++) { string s = *it; ... 阅读全文
posted @ 2013-10-19 16:22 summer_zhou 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 用回溯法求解。1.Permutations vector > permute(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(num.empty()) return res; vector bvisited(num.size(),false); vector permu; dfs(0,num,bv... 阅读全文
posted @ 2013-10-19 16:09 summer_zhou 阅读(210) 评论(0) 推荐(0) 编辑