2013年6月3日
摘要: 1 // 16ms 2 /** 3 * Definition for binary tree 4 * struct TreeNode { 5 * int val; 6 * TreeNode *left; 7 * TreeNode *right; 8 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 9 * };10 */11 class Solution {12 public:13 vector<int> inorderTraversal(TreeNode *root) {14... 阅读全文
posted @ 2013-06-03 20:44 宇睿 阅读(111) 评论(0) 推荐(0) 编辑
摘要: //开始竟然忘了加return 了!! 152ms通过大的 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 13 TreeNode *buildTree(vec... 阅读全文
posted @ 2013-06-03 20:06 宇睿 阅读(134) 评论(0) 推荐(0) 编辑
摘要: //应该用两个栈 16ms 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 vector<vector<int> > zigzagLevelOrder(TreeN... 阅读全文
posted @ 2013-06-03 19:15 宇睿 阅读(135) 评论(0) 推荐(0) 编辑
摘要: // 173ms 1 /** 2 * Definition for binary tree with next pointer. 3 * struct TreeLinkNode { 4 * int val; 5 * TreeLinkNode *left, *right, *next; 6 * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 int flag;12 TreeLinkNo... 阅读全文
posted @ 2013-06-03 16:47 宇睿 阅读(133) 评论(0) 推荐(0) 编辑
摘要: // 4ms 120ms 1 /** 2 * Definition for binary tree with next pointer. 3 * struct TreeLinkNode { 4 * int val; 5 * TreeLinkNode *left, *right, *next; 6 * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 void connect(TreeLink... 阅读全文
posted @ 2013-06-03 15:35 宇睿 阅读(118) 评论(0) 推荐(0) 编辑
摘要: // 4ms 1 class Solution { 2 public: 3 vector<int> getRow(int rowIndex) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector<int> v; 7 v.push_back(1); 8 if(rowIndex==0) 9 return v;10 v.push_back(1... 阅读全文
posted @ 2013-06-03 15:12 宇睿 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 vector<vector<int> > generate(int numRows) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector<int> v ; 7 vector<vector<int> > re; 8 if(numRows==0) 9 return re;10 ... 阅读全文
posted @ 2013-06-03 14:53 宇睿 阅读(124) 评论(0) 推荐(0) 编辑
摘要: //小的能过,大的内存超限,故大于3000则不处理 :) 1 char edge[3000][3000]={0}; 2 int len[3000]={0}; 3 4 class Solution { 5 public: 6 7 int countL; 8 int findShort() 9 {10 int i,j,k;11 len[0]=0;12 vector<int> q,qq;13 q.push_back(0);14 for( ;q.size(); )15 ... 阅读全文
posted @ 2013-06-03 13:02 宇睿 阅读(177) 评论(0) 推荐(0) 编辑
摘要: // 56ms 1 class Solution { 2 public: 3 4 void DFS(vector<vector<char>> &v,int i,int j) 5 { 6 if(v[i][j]=='O') 7 { 8 v[i][j]='Q'; 9 if(i>0)10 DFS(v,i-1,j);11 if(i<v.size()-1)12 DFS(v,i+1,j);13 ... 阅读全文
posted @ 2013-06-03 10:47 宇睿 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * Interval(int s, int e) : start(s), end(e) {} 8 * }; 9 */10 class Solution;11 bool incmp(struct Interval a,struct Interval b)12 {13 ... 阅读全文
posted @ 2013-06-03 10:31 宇睿 阅读(152) 评论(0) 推荐(0) 编辑
摘要: //风格比较差,用时较长:712ms 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * Interval(int s, int e) : start(s), end(e) {} 8 * }; 9 */10 class Solution;11 bool incmp(struct Interval a,struct Interval b)... 阅读全文
posted @ 2013-06-03 10:23 宇睿 阅读(175) 评论(0) 推荐(0) 编辑
摘要: //这个方案目前超时,需要其他方法 1 char vf[100][100]; 2 3 class Solution { 4 public: 5 6 7 bool DFS(vector<vector<char> > &v,int i,int j,const char *p) 8 { 9 bool r; 10 11 12 if(v[i][j]!=p[0]) 13 return false; 14 if((v[i][j]==p[0])&&(p[1]... 阅读全文
posted @ 2013-06-03 00:52 宇睿 阅读(145) 评论(0) 推荐(0) 编辑