摘要:
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); ... 阅读全文
摘要:
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 阅读全文
摘要:
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_... 阅读全文
摘要:
递归 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... 阅读全文
摘要:
问题的本质就是:树的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... 阅读全文
摘要:
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) { ... 阅读全文
摘要:
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; ... 阅读全文
摘要:
//注意容器的空间,如果没有预设好,[]访问会出错的。。。。---这个很容易出问题。 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++) { ... 阅读全文