摘要:
解法一: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... 阅读全文
摘要:
解法一:递归int countNodes(TreeNode* root){ if (root == NULL) return 0; TreeNode *pLeft = root->left; TreeNode *pRight = root->right; ... 阅读全文
摘要:
解法一:非递归 1 vector preorderTraversal(TreeNode* root) 2 { 3 vector res; 4 if (root == NULL) 5 return res; 6 7 stack node_stack; 8 ... 阅读全文
摘要:
1 struct TreeNode { 2 char val; 3 TreeNode *left; 4 TreeNode *right; 5 int visitCount; //节点访问次数,后序遍历会用到 6 TreeNode(c... 阅读全文
摘要:
1 //occupyed_1检查行是否占用 2 //occupyed_2检查列是否占用 3 //occupyed_3检查块是否占用 4 bool isValidSudoku(vector>& board) 5 { 6 int occupyed_1[9][9], occupyed_2[9][... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 ... 阅读全文