摘要: BFS int ladderLength(string start, string end, unordered_set &dict) { // Note: The Solution object is instantiated only once and is reused by each test case. int len = 1; unordered_set strs; queue q; q.push(start); strs.insert(start); ... 阅读全文
posted @ 2013-10-23 22:57 summer_zhou 阅读(173) 评论(0) 推荐(0) 编辑
摘要: vector letterCombinations(string digits) { // Note: The Solution object is instantiated only once and is reused by each test case. string maps[] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector res; dfs(0,di 阅读全文
posted @ 2013-10-23 20:02 summer_zhou 阅读(148) 评论(0) 推荐(0) 编辑
摘要: void setZeroes(vector > &matrix) { // Note: The Solution object is instantiated only once and is reused by each test case. if(matrix.empty()) return; int m = matrix.size(); int n = matrix[0].size(); bool first_row,first_col; first_row = first_... 阅读全文
posted @ 2013-10-23 19:18 summer_zhou 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 递归 void flatten(TreeNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. flat(root); } TreeNode* flat(TreeNode* root) { if(!root) return NULL; TreeNode* left_tail = flat(root->left); TreeNo... 阅读全文
posted @ 2013-10-23 18:56 summer_zhou 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 问题的本质就是:树的level-order遍历 TreeLinkNode* getNextSibling(TreeLinkNode* cur) { while(cur) { if(cur->left) return cur->left; if(cur->right) return cur->right; cur = cur->next; } return NULL; }class Solution {public: void connect(TreeLinkNode... 阅读全文
posted @ 2013-10-23 15:10 summer_zhou 阅读(162) 评论(0) 推荐(0) 编辑
摘要: void connect(TreeLinkNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!root) return; TreeLinkNode* first,*cur; first = cur = root; while(cur) { if(cur->left) { ... 阅读全文
posted @ 2013-10-23 14:47 summer_zhou 阅读(166) 评论(0) 推荐(0) 编辑
摘要: vector getRow(int rowIndex) { // Note: The Solution object is instantiated only once and is reused by each test case. if(rowIndex(); vector res(rowIndex+1); res[0] = 1; for(int i=1;i0;j--) res[j] += res[j-1]; res[0] = 1; ... 阅读全文
posted @ 2013-10-23 14:30 summer_zhou 阅读(130) 评论(0) 推荐(0) 编辑
摘要: //注意容器的空间,如果没有预设好,[]访问会出错的。。。。---这个很容易出问题。 vector > generate(int numRows) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(numRows()); res[0].push_back(1); for(int i=1;i<numRows;i++) { ... 阅读全文
posted @ 2013-10-23 11:50 summer_zhou 阅读(135) 评论(0) 推荐(0) 编辑