摘要: 解法一:O(N) 1 vector twoSum(vector& nums, int target) 2 { 3 unordered_map numsHash; 4 vector res; 5 6 for (int i = 0; i twoSum(vector& nums... 阅读全文
posted @ 2015-07-10 15:20 QingLiXueShi 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 解法一:递归int countNodes(TreeNode* root){ if (root == NULL) return 0; TreeNode *pLeft = root->left; TreeNode *pRight = root->right; ... 阅读全文
posted @ 2015-07-09 17:14 QingLiXueShi 阅读(444) 评论(0) 推荐(0) 编辑
摘要: 解法一:非递归 1 vector preorderTraversal(TreeNode* root) 2 { 3 vector res; 4 if (root == NULL) 5 return res; 6 7 stack node_stack; 8 ... 阅读全文
posted @ 2015-07-09 11:07 QingLiXueShi 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 1 struct TreeNode { 2 char val; 3 TreeNode *left; 4 TreeNode *right; 5 int visitCount; //节点访问次数,后序遍历会用到 6 TreeNode(c... 阅读全文
posted @ 2015-07-09 10:46 QingLiXueShi 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 1 //occupyed_1检查行是否占用 2 //occupyed_2检查列是否占用 3 //occupyed_3检查块是否占用 4 bool isValidSudoku(vector>& board) 5 { 6 int occupyed_1[9][9], occupyed_2[9][... 阅读全文
posted @ 2015-07-08 21:33 QingLiXueShi 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 1 enum status{VALID = 0, INVALID}; 2 int g_status; 3 4 long long SubStrToInt(const char* str, bool minus) 5 { 6 long long num = 0; 7 int fl... 阅读全文
posted @ 2015-07-08 16:48 QingLiXueShi 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 1 class Queue { 2 public: 3 // Push element x to the back of queue. 4 void push(int x) { 5 while (!nums.empty()) { 6 nums... 阅读全文
posted @ 2015-07-08 14:38 QingLiXueShi 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1 class Stack { 2 public: 3 // Push element x onto stack. 4 void push(int x) { 5 int len = nums.size(); 6 nums.push(x); 7 ... 阅读全文
posted @ 2015-07-08 11:29 QingLiXueShi 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 1 string countAndSay(int n) 2 { 3 string res; 4 if (n 1) { 9 int len = res.size();10 int i, j;11 string resTmp;12 13... 阅读全文
posted @ 2015-07-07 20:08 QingLiXueShi 阅读(268) 评论(0) 推荐(0) 编辑
摘要: 寻找数组A的和最大的非空连续子数组。例如:A[] = {1, -2, 3, 10, -4, 7, 2, -5}的最大子数组为3, 10, -4, 7, 2,其最大和为18。数组元素都为负时,返回最大负值。解法一:暴力枚举,O(N^2) 1 //left,最大子数组左端 2 //right,最大子数组... 阅读全文
posted @ 2015-07-07 18:30 QingLiXueShi 阅读(266) 评论(0) 推荐(0) 编辑