diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fe4b463 Binary files /dev/null and b/.DS_Store differ diff --git a/AlgorithmCode b/AlgorithmCode new file mode 160000 index 0000000..7f0f0f4 --- /dev/null +++ b/AlgorithmCode @@ -0,0 +1 @@ +Subproject commit 7f0f0f46dbe90bbbeb1fb31635136252eae7e0dd diff --git a/MinStack.cpp b/MinStack.cpp new file mode 100644 index 0000000..980ee13 --- /dev/null +++ b/MinStack.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +stack datas; +stack mins; + +void push(int x) { + datas.push(x); + if (mins.empty() || x < mins.top()) + { + mins.push(x); + } + else + { + mins.push(mins.top()); + } +} + +void pop() { + if (!mins.empty() && !datas.empty()) + { + mins.pop(); + datas.pop(); + } +} + +int top() { + return datas.top(); +} + +int min() { + return mins.top(); +} \ No newline at end of file diff --git a/buildTree.cpp b/buildTree.cpp new file mode 100644 index 0000000..54ccc03 --- /dev/null +++ b/buildTree.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +void buildTree(TreeNode* &root, vector& nums, int lens, int i) +{ + if (i >= lens) + { + return; + } + root = new TreeNode(nums[i]); + buildTree(root->left, nums, lens, i * 2 + 1); + buildTree(root->right, nums, lens, i * 2 + 2); +} + +void inorderTravel(TreeNode* root, vector& res) +{ + if (root == NULL) + { + return; + } + + if (root->left != NULL) + { + inorderTravel(root->left, res); + } + + res.push_back(root->val); + + if (root->right != NULL) + { + inorderTravel(root->right, res); + } +} + +TreeNode* Trees(TreeNode* root, vector& nums) +{ + int lens = nums.size(); + buildTree(root, nums, lens, 0); + return root; +} + +int main() +{ + vector res; + vector nums = {1, 2, 3, 4, 5, 6, 7, 8}; + TreeNode* root; + root = Trees(root, nums); + inorderTravel(root, res); + return 0; +} + diff --git a/buildTree.exe b/buildTree.exe new file mode 100644 index 0000000..2b4d9e6 Binary files /dev/null and b/buildTree.exe differ diff --git a/code/LCOF.cpp b/code/LCOF.cpp new file mode 100644 index 0000000..40fd191 --- /dev/null +++ b/code/LCOF.cpp @@ -0,0 +1,189 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int findRepeatNumber(vector& nums) +{ + int lens = nums.size(); + for(int i = 0; i < lens; i++){ + while (nums[i] != i){ + if (nums[i] == nums[nums[i]]) + { + return nums[i]; + } + swap(nums[i], nums[nums[i]]); + } + } + return 0; +} + + +bool containsDuplicate_one(vector& nums) +{ + unordered_set dup(nums.begin(), nums.end()); + if (dup.size() != nums.size()){ + return true; + } + return false; +} + +bool containsDuplicate(vector& nums) +{ + int lens = nums.size(); + unordered_map dup; + if (lens < 2){ + return false; + } + + for(int i = 0; i < lens; i++){ + dup[nums[i]]++; + if(dup[nums[i]] > 1){ + return true; + } + } + return false; +} + +bool Find(int* matrix, int rows, int columns, int numbers) +{ + bool found = false; + if (matrix != nullptr && rows > 0 && columns > 0) + { + int row = 0; + int column = columns - 1; + while (row < rows && columns>= 0) + { + if (matrix[rows * columns + columns] == numbers){ + found = true; + break; + } + else if(matrix[row * columns + column] > numbers){ + column--; + } + else{ + row++; + } + } + } + return found; +} + +// searchMatrix +bool findNumberIn2DArray(vector>& matrix, int target) +{ + if (matrix.empty()) + { + return false; + } + + int rows = matrix.size(); + int columns = matrix[0].size(); + int row = 0; + int column = columns - 1; + if(rows > 0 || columns > 0){ + while (row < rows && column > -1){ + if (matrix[row][column] == target) + { + return true; + } + else if (matrix[row][column] > target) + { + column--; + } + else + { + row++; + } + } + } + return false; +} + +// void replaceBlank(char string[], int length) +// { +// if (string == nullptr || length <= 0) +// { +// return; +// } +// int rawLength = 0; +// int numBlank = 0; +// int i = 0; +// while (string[i] != '\0') +// { +// rawLength++; +// if(string[i] == ' '){ +// numBlank++; +// } +// i++; +// } + +// int length = rawLength + numBlank * 2; +// int p1 = rawLength; +// int p2 = length; +// while (p1 > -1 && p2 > p1) +// { +// if(string[p1] = ' '){ +// string[p2--] = '0'; +// string[p2--] = '2'; +// string[p2--] = '%'; +// } +// else +// { +// string[p2--] = string[p1]; +// } +// p1--; +// } + + + +// } + +string replaceSpace(string s) +{ + int rawLength = s.length(); + int numBlank = 0; + if (rawLength == 0) + { + return s; + } + + for(int i = 0; i < rawLength; i++){ + if (s[i] == ' '){ + numBlank++; + } + } + + int p2 = rawLength + 2 * numBlank; + int p1 = rawLength; + char string[p2]; + + while (p1 > -1 && p2 > p1) + { + if(s[p1] == ' '){ + string[p2--] = '0'; + string[p2--] = '2'; + string[p2--] = '%'; + } + else + { + string[p2--] = s[p1]; + } + p1--; + } + printf("%s",string); + return s; +} + +int main() +{ + // vector> nums = {{-5}}; + // findNumberIn2DArray(nums,-5); + replaceSpace("We are happy."); + return 0; +} diff --git a/code/LCOF.exe b/code/LCOF.exe new file mode 100644 index 0000000..7c7c5be Binary files /dev/null and b/code/LCOF.exe differ diff --git a/code/binaryTree.cpp b/code/binaryTree.cpp new file mode 100644 index 0000000..1c0db8d --- /dev/null +++ b/code/binaryTree.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +struct TreeNode{ + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x): val(x),left(NULL),right(NULL){} +}; + +// unordered_map maps; + +// TreeNode* buildTree2(int preL, int inL, int preR) +// { + +// } + +// TreeNode* buildTree(vector& preorder, vector& inorder) +// { +// for (int i = 0; i < inorder.size(); i++) +// { +// maps[inorder[i]] = i; +// } + +// return buildTree2(0, 0, inorder.size() - 1, preorder); +// } +class Solution{ + public: + unordered_mapmaps; + vector preorder; + + TreeNode* buildTree(vector& preorder, vector& inorder) + { + for (int i = 0; i < inorder.size(); i++) + { + maps[inorder[i]] = i; + } + TreeNode* root = buildTree2(0,inorder.size() - 1,0, preorder.size() - 1,preorder); + return root; + } + + TreeNode* buildTree2(int preL, int preR, int inL, int inR, vector preorder) + { + if (preL > preR || inL > inR){ + return NULL; + } + + int middle = preorder[preL]; + TreeNode* root = new TreeNode(middle); + int index = maps[middle]; + root->left = buildTree2(preL + 1, preL + (index - inL), inL, index - 1); + root->right = buildTree2(preL + (index - inL) + 1, preR, index + 1, inR); + return root; + } + + vector PrintFromTopToBottom(TreeNode* root) { + vector a; + queue tree; + if(root==NULL)return a; + TreeNode* r; + tree.push(root); + while(tree.size()){ + r=tree.front(); + a.push_back(r->val); + if(r->left!=NULL){ + printf("%d",r->left); + tree.push(r->left); + } + if(r->right!=NULL){ + printf("%d",r->right); + tree.push(r->right); + } + tree.pop();// + } + return a; + } +}; + +int main() +{ + Solution* a = new Solution(); + vector b = {3,9,20,15,7}; + vector c = {9,3,15,20,7}; + a->preorder = b; + TreeNode* root = a->buildTree(b,c); + a->PrintFromTopToBottom(root); + return 0; +} + +// unordered_map map; + +// TreeNode* buildTree2(int preL, int preR, int inL,int inR, vector& preorder, vector& inorder) +// { +// if(preL > preR || inL > inR){ +// return NULL; +// } + +// int middle = preorder[preL]; +// TreeNode* root = new TreeNode(middle); +// auto it = map.find(middle); +// int index = it->first; + +// root->left = buildTree2(preL + 1, preL + (index - inL), inL, index - 1, preorder, inorder); +// root->right = buildTree2(preL + (index - inL) + 1, preR, index + 1, inR, preorder, inorder); +// return root; +// } + +// TreeNode* buildTree(vector& preorder, vector& inorder) +// { +// int preLen = preorder.size(); +// int inLen = inorder.size(); + +// for (int i = 0; i < inLen; i++) +// { +// map[i] = inorder[i]; +// } + +// return buildTree2(0, preLen - 1, 0, inLen - 1, preorder, inorder); + +// } diff --git a/code/binaryTree.exe b/code/binaryTree.exe new file mode 100644 index 0000000..1e64b71 Binary files /dev/null and b/code/binaryTree.exe differ diff --git a/code/constructTree.cpp b/code/constructTree.cpp new file mode 100644 index 0000000..864a11f --- /dev/null +++ b/code/constructTree.cpp @@ -0,0 +1,10 @@ +#include +#include + +struct TreeNode{ + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x): val(x),left(NULL),right(NULL){} +}; + diff --git a/code/cuttingRope.cpp b/code/cuttingRope.cpp new file mode 100644 index 0000000..be307cb --- /dev/null +++ b/code/cuttingRope.cpp @@ -0,0 +1,122 @@ +#include +#include +#include +using namespace std; + +// int cuttingRope(int n) +// { + +// if (n < 2) +// { +// return 0; +// } +// if (n == 2) +// { +// return 1; +// } +// if (n == 3) +// { +// return 2; +// } + +// int *res = new int[n + 1]; +// int max = 0; +// res[1] = 1; +// res[2] = 2; +// res[3] = 3; + +// for (int i = 4; i <= n; i++) +// { max = 0; +// for (int j = 1; j <= i/2; j++) +// { +// int tmp = res[j] * res[i - j]; +// if (max < tmp){ +// max = tmp; +// } +// } +// res[i] = max; +// } +// max = res[n]; +// return max; +// } + + +// int pows(int n, int m) +// { +// int res = 1; +// if (m == 3) +// { +// for (int i = 0; i < n; i++) +// { +// res = (res * 3) % 1000000007; +// } +// return res; +// } +// else +// { +// for (int i = 0; i < n; i++) +// { +// res = (res * 2) % 1000000007; +// } +// return res; +// } +// } + + +// int cuttingRope(int n) +// { + // if (n < 2) + // { + // return 1; + // } + // if (n == 2) + // { + // return 1; + // } + // if (n == 3) + // { + // return 2; + // } + +// int timeThree = n / 3; +// if (n - timeThree * 3 == 1) +// { +// timeThree--; +// } +// int timeTwo = (n - timeThree * 3) / 2; +// int max = pows(timeThree, 3) * pows(timeTwo, 2); +// return max % 1000000007; +// } + +int cuttingRope(int n) +{ + if (n < 2) + { + return 1; + } + if (n == 2) + { + return 1; + } + if (n == 3) + { + return 2; + } + + long long res = 1; + while (n > 4) + { + res *= 3; + res %= 1000000007; + n -= 3; + } + return res * n % 1000000007; + +} + +int main() +{ + int n = cuttingRope(127); + printf("%d",n); + return 0; +} \ No newline at end of file diff --git a/code/cuttingRope.exe b/code/cuttingRope.exe new file mode 100644 index 0000000..bfa1d81 Binary files /dev/null and b/code/cuttingRope.exe differ diff --git a/code/fib.cpp b/code/fib.cpp new file mode 100644 index 0000000..088dd9c --- /dev/null +++ b/code/fib.cpp @@ -0,0 +1,68 @@ +#include + +// int fib2(int n){ +// if(n == 0){ +// return 0; +// } +// else if(n == 1) +// { +// return 1; +// } +// else +// { +// return fib(n - 1) + fib(n - 2); +// } + +// } + +int fib(int n) +{ + if (n == 0) + { + return 0; + } + else if(n == 1){ + return 1; + } + else + { + long long fib_one = 1; + long long fib_two = 0; + long long fibn = 0; + for (int i = 2; i <= n; i++) + { + fibn = (fib_one + fib_two)%1000000007; + fib_two = fib_one; + fib_one = fibn; + } + return fibn; + } +} + +int numWays(int n) +{ + if(n == 0){ + return 1; + } + if (n == 1){ + return 1; + } + int one = 1; + int two = 1; + int way = 0; + for (int i = 2; i <= n; i++) + { + way = (one + two) % 1000000007; + one = two; + two = way; + } + return way; +} + + +int main() +{ + int c = numWays(2); + printf("%d",c); + return 0; +} \ No newline at end of file diff --git a/code/fib.exe b/code/fib.exe new file mode 100644 index 0000000..b0f29e5 Binary files /dev/null and b/code/fib.exe differ diff --git a/code/hammingWeight.cpp b/code/hammingWeight.cpp new file mode 100644 index 0000000..8703403 --- /dev/null +++ b/code/hammingWeight.cpp @@ -0,0 +1,33 @@ +#include +#include + +// int hammingWeight(uint32_t n) { +// int num = 0; +// while (n) +// { +// if (n & 1) +// { +// num++; +// } +// n = n >> 1; +// } +// return num; +// } + +int hammingWeight(uint32_t n) +{ + int num = 0; + while (n) + { + n = (n - 1) & n; + num++; + } + return num; +} + +int main() +{ + int num = hammingWeight(00000000000000000000000000001011); + printf("%d",num); + return 0; +} \ No newline at end of file diff --git a/code/hammingWeight.exe b/code/hammingWeight.exe new file mode 100644 index 0000000..e48072d Binary files /dev/null and b/code/hammingWeight.exe differ diff --git a/code/hashpath.cpp b/code/hashpath.cpp new file mode 100644 index 0000000..a34f443 --- /dev/null +++ b/code/hashpath.cpp @@ -0,0 +1,52 @@ +#include +// #include +#include +#include +#include +#include +#include +using namespace std; + +bool hasPath(char* matrix, int rows, int cols, char* str) +{ + bool *visited = new bool[rows * cols]; + memset(visited, 0, rows * cols); + + int lens = 0; + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + if (hasPath(matrix, rows, cols, i, j, str, lens, visited)) + { + return true; + } + + } + } + delete[] visited; + return false; +} + +bool hasPathCore(const char* matrix, int rows, int cols, int row, int col, + const char* str, int& lens, bool* visited) +{ + if(str[lens] == '\0') return true; + bool haspath = false; + if (row >= 0 && row < rows && col >= 0 && col < cols + && matrix[row * cols + col] == str[lens] + && !visited[row * cols + col]) + { + lens++; + visited[row * cols + col] = true; + haspath = hasPathCore(matrix, rows, cols, row, col - 1, str, lens, visited) + ||hasPathCore(matrix, rows, cols, row - 1, col, str, lens, visited) + ||hasPathCore(matrix, rows, cols, row, col + 1, str, lens, visited) + ||hasPathCore(matrix, rows, cols, row + 1, col, str, lens, visited); + if(!haspath){ + lens--; + visited[row * cols + col] = false; + } + } + return haspath; +} \ No newline at end of file diff --git a/code/list.cpp b/code/list.cpp new file mode 100644 index 0000000..d03b986 --- /dev/null +++ b/code/list.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +using namespace std; + +struct Listnode{ + int val; + Listnode* next; +}; + +void add_tail(Listnode* &head, int value) +{ + Listnode* newNode = new Listnode(); + newNode->val = value; + newNode->next = NULL; + + if(head == NULL){ + head = newNode; + } + else{ + Listnode* p = head; + while (p->next != NULL) + { + p = p->next; + } + p->next = newNode; + } +} + +vector reversePrint(Listnode* head) +{ + stack nodes; + Listnode* p = head; + while (p != nullptr) + { + nodes.push(p); + p = p->next; + } + while (!nodes.empty()) + { + p = nodes.top(); + printf("%d\t",p->val); + nodes.pop(); + } + +} + + +int main() +{ + Listnode* head =NULL; + add_tail(head, 10); + if (head != NULL) + { + cout << head->val << endl; + } + else + { + cout << "head is null"< +#include +using namespace std; + + struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} + }; + +int min_dif = 100; +int temp1 = -100; +int temp2 = -100; + +int minDiffInBST(TreeNode* root) { + return inorder(root); +} + +int inorder(TreeNode* r) +{ + if(!r) + return min_dif; + if(r -> left) + inorder(r -> left); + temp1 = temp2; + temp2 = r -> val; + min_dif = min(min_dif, temp2 - temp1); + if(r -> right) + inorder(r -> right); + return min_dif; +} + +int main() +{ + int nums[] = {4,2,6,1,3,NULL,NULL}; + TreeNode* nodes = nums; + int res = minDiffInBST(nodes); +} \ No newline at end of file diff --git a/code/minnumber.cpp b/code/minnumber.cpp new file mode 100644 index 0000000..618ad03 --- /dev/null +++ b/code/minnumber.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; + +int minArray(vector& nums) +{ + int length = nums.size(); + if (length < 0){ + return 0; + } + int p1 = 0; + int p2 = length - 1; + int pm = p1; + + while (nums[p1] >= nums[p2]) + { + if (p2 - p1 == 1) + { + pm = p2; + break; + } + pm = (p1 + p2) / 2; + + if (nums[p1] == nums[p2] && nums[p1] == nums[pm]){ + int res = nums[p1]; + for (int i = 0; i <= p2; i++){ + if (res > nums[i]){ + res = nums[i]; + } + } + return res; + } + + if (nums[pm] >= nums[p1]) + { + p1 = pm; + } + else if(nums[pm] <= nums[p2]) + { + p2 = pm; + } + } + return nums[pm]; +} \ No newline at end of file diff --git a/code/movingCount.cpp b/code/movingCount.cpp new file mode 100644 index 0000000..70d312b --- /dev/null +++ b/code/movingCount.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +using namespace std; + +int movingCount(int m, int n, int k) +{ + int movingCountCore(int threshold, int rows, int cols, int i, int j, bool *visited); + int rows = m, cols = n; + int threshold = k; + + if (threshold < 0|| rows < 0 || cols < 0) + { + return 0; + } + + bool *visited = new bool[rows * cols]; + memset(visited, 0, rows * cols); + // for (int i = 0; i < rows * cols; i++) + // { + // visited[i] = false; + // } + + + int count = movingCountCore(threshold, rows, cols, 0, 0, visited); + return count; +} + +int movingCountCore(int threshold, int rows, int cols, int i, int j, bool *visited) +{ + bool check(int threshold, int rows, int cols, int i , int j, bool *visited); + int count = 0; + if (check(threshold, rows, cols, i, j, visited)) + { + visited[i * cols + j] = true; + int one = movingCountCore(threshold,rows, cols, i - 1, j, visited); + int two = movingCountCore(threshold,rows, cols, i, j - 1, visited); + int three = movingCountCore(threshold, rows, cols, i + 1, j, visited); + int four = movingCountCore(threshold, rows, cols, i, j + 1,visited); + count = 1 + one + two + three + four; + } + return count; +} + +bool check(int threshold, int rows, int cols, int i , int j, bool *visited) +{ + int getSum(int row, int col); + if (i >= 0 && i < rows && j >= 0 && j < cols && getSum(i ,j) <= threshold && !visited[i * cols + j]) + { + return true; + } + return false; +} + +int getSum(int row, int col) +{ + int sum = 0; + while (row > 0) + { + sum += row % 10; + row /= 10; + } + while (col > 0) + { + sum += col % 10; + col /= 10; + } + return sum; +} + +int main() +{ + int row = 2, col = 3, threshold = 1; + printf("%d",movingCount(row,col,threshold)); + return 0; +} \ No newline at end of file diff --git a/code/movingCount.exe b/code/movingCount.exe new file mode 100644 index 0000000..81cac24 Binary files /dev/null and b/code/movingCount.exe differ diff --git a/code/myPow.cpp b/code/myPow.cpp new file mode 100644 index 0000000..73ed4e8 --- /dev/null +++ b/code/myPow.cpp @@ -0,0 +1,47 @@ +#include +#include +using namespace std; + +double myPow(double x, int n) +{ + if (n < 0) + { + int res = myPowCore(x, n); + return 1/res; + } + else + { + int res = myPowCore(x, n); + return res; + } +} + +double myPowCore(double x, int n) { + if (n == 0) + { + return 1; + } + else if (n == 1) + { + return x; + } + else + { + double res = myPow(x, n >> 1); + res *= res; + if (n & 1 == 1) + { + res *= x; + } + return res; + } +} + + + +int main() +{ + int res = myPow(2,12); + printf("%d",res); + return 0; +} \ No newline at end of file diff --git a/code/myPow.exe b/code/myPow.exe new file mode 100644 index 0000000..887bd42 Binary files /dev/null and b/code/myPow.exe differ diff --git a/code/sort_again.cpp b/code/sort_again.cpp new file mode 100644 index 0000000..39f0be6 --- /dev/null +++ b/code/sort_again.cpp @@ -0,0 +1,96 @@ +#include +#include +using namespace std; + +// void quickSort(int* nums, int left, int right) +// { +// if (left < right) +// { +// int i = left, j = right; +// int x = nums[left]; + +// while (i < j) +// { +// while (i < j && nums[j] >= x){ +// j--; +// } +// if (i < j){ +// nums[i++] = nums[j]; +// } +// while (i < j && nums[i] <= x){ +// i++; +// } +// if (i < j){ +// nums[j--] = nums[i]; +// } +// } +// nums[i] = x; +// quickSort(nums, left, i - 1); +// quickSort(nums, i + 1, right); +// } +// } + +int partition(vector& nums, int left, int right) +{ + int i = left, j = right; + int x = nums[left]; + + while (i < j) + { + while (i < j && nums[j] >= x){ + j--; + } + if (i < j){ + nums[i++] = nums[j]; + } + while (i < j && nums[i] <= x){ + i++; + } + if (i < j){ + nums[j--] = nums[i]; + } + } + nums[i] = x; + return i; +} + +int partition_two(vector& nums, int left, int right) +{ + int pivot = nums[left]; + int i = left + 1, j = right; + while (i < j) + { + while(i < j && nums[i] <= pivot) i++; + while(i < j && nums[j] >= pivot) j--; + if (i < j){ + swap(nums[i], nums[j]); + } + } + swap(nums[i], nums[left]); + return i; +} + +vector quickSort(vector& nums, int left, int right) +{ + if (left < right) + { + int i = partition_two(nums, left, right); + quickSort(nums, left, i - 1); + quickSort(nums, i + 1, right); + } +} + + vector sortArray(vector& nums) { + int i = 0, j = nums.size() - 1; + quickSort(nums, i, j); + return nums; +} + +int main() +{ + vector num = {72,6,57,88,60,42,83,73,48,85}; + int nums[10] = {72,6,57,88,60,42,83,73,48,85}; + quickSort(num, 0, 9); + return 0; + +} \ No newline at end of file diff --git a/code/sort_again.exe b/code/sort_again.exe new file mode 100644 index 0000000..4d19aef Binary files /dev/null and b/code/sort_again.exe differ diff --git a/code/stack_to_queue.cpp b/code/stack_to_queue.cpp new file mode 100644 index 0000000..9fd0af5 --- /dev/null +++ b/code/stack_to_queue.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +class CQueue { + stack s1; + stack s2; +public: + CQueue() { + + } + + void appendTail(int value) { + s1.push(value); + } + + int deleteHead() { + if (s2.empty()) + { + if(s1.empty()){ + return -1; + } + else{ + while (!s1.empty()) + { + s2.push(s1.top()); + s1.pop(); + } + } + } + int data = s2.top(); + s2.pop(); + return data; + } +}; + + +class CQueue { + stack stack_one; + stack stack_two; +public: + CQueue() { + + } + + void appendTail(int value) { + stack_one.push(value); + } + + int deleteHead() { + if (stack_two.empty()) + { + while (!stack_one.empty()) + { + int data = stack_one.top(); + stack_two.push(data); + stack_one.pop(); + } + } + else + { + int data = stack_two.top(); + stack_two.pop(); + } + return data; + } +}; \ No newline at end of file diff --git a/code/test.cpp b/code/test.cpp new file mode 100644 index 0000000..8d307bb --- /dev/null +++ b/code/test.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +bool exist(vector>& board, string word) { + int rows = board.size(); + int cols = board[0].size(); + int lens = 0; + + bool *visited = new bool[rows * cols]; + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + if (hasPathCore(board, rows, cols, i, j, word, lens, visited)) + { + return true; + } + } + } + delete[] visited; + return false; +} + +bool hasPathCore(const char* matrix, int rows, int cols, int i, int j, + const char* str, int& lens, bool* visited) +{ + if(str[lens] == '\0') return true; + bool haspath = false; + if (i >= 0 && i < rows && j >=0 && j < cols + && matrix[i * cols + j] == str[lens] && !visited[i * cols + j]) + { + lens++; + visited[i * cols + j] = true; + haspath = hasPathCore(matrix, rows, cols, i, j - 1, str, lens, visited) + ||hasPathCore(matrix, rows, cols, i - 1, j, str, lens, visited) + ||hasPathCore(matrix, rows, cols, i + 1, j, str, lens , visited) + ||hasPathCore(matrix, rows, cols, i + 1, j, str, lens, visited); + + if (!haspath) + { + lens--; + visited[i * cols +j] = false; + } + } + return haspath; +} \ No newline at end of file diff --git a/constructTrees.cpp b/constructTrees.cpp new file mode 100644 index 0000000..92e70d7 --- /dev/null +++ b/constructTrees.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +vector res; + +TreeNode* constructTrees(TreeNode*& root, vector& nums,int lens, int i) +{ + if (i > lens){ + return root; + } + + root = new TreeNode(nums[i]); + constructTrees(root->left, nums, lens, 2 * i + 1); + constructTrees(root->right, nums, lens, 2 * i + 2); + i--; +} + +void inorderTravel(TreeNode* root) +{ + if (root == NULL) + { + return; + } + + if (root->left != NULL) + { + inorderTravel(root->left); + } + + res.push_back(root->val); + + if (root->right != NULL) + { + inorderTravel(root->right); + } +} + +TreeNode* Trees(TreeNode*& root, vector& nums) +{ + int lens = nums.size() - 1; + TreeNode* roots = constructTrees(root, nums, lens, 0); + return roots; +} + +int main() +{ + vector nums = {1, 2, 3, 4, 5, 6, 7, 8}; + // int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; + // vector nums(a,a+7); + TreeNode* root; + Trees(root, nums); + return 0; +} \ No newline at end of file diff --git a/deleteNode.cpp b/deleteNode.cpp new file mode 100644 index 0000000..ade438e --- /dev/null +++ b/deleteNode.cpp @@ -0,0 +1,60 @@ +#include +#include +using namespace std; + + struct ListNode { + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +ListNode* deleteNode(ListNode* head, int val) { + ListNode* p = new ListNode(-1); + p = head; + + if (p == nullptr) + { + return head; + } + if (p->val == val) + { + return nullptr; + } + + while (p->next != nullptr && p->next->val != val) + { + p = p->next; + } + if (p->next->next != nullptr) + { + p->next = p->next->next; + } + else + { + p->next = nullptr; + } + + return head; +} + +ListNode* createNode(ListNode* head, vector& nums) +{ + head = new ListNode(0); + ListNode* p = head; + for (int i = 0; i < nums.size(); i++) + { + ListNode* p2 = new ListNode(nums[i]); + p->next = p2; + p = p2; + } + return head; +} + +int main() +{ + vector nums = {4,5,1,9}; + ListNode* p; + p = createNode(p, nums); + deleteNode(p, 1); + return 0; +} diff --git a/deleteNode.exe b/deleteNode.exe new file mode 100644 index 0000000..97e77f5 Binary files /dev/null and b/deleteNode.exe differ diff --git a/hasSubtree.cpp b/hasSubtree.cpp new file mode 100644 index 0000000..a6ab8d4 --- /dev/null +++ b/hasSubtree.cpp @@ -0,0 +1,49 @@ +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} + }; + +bool hasTree(TreeNode* a, TreeNode* b) +{ + if (b == nullptr) + { + return true; + } + if (a == nullptr) + { + return false; + } + if (!(a->val == b->val)) + { + return false; + } + return hasTree(a->left, b->left) && hasTree(a->right, b->right); +} + + +bool isSubStructure(TreeNode* A, TreeNode* B) { + bool res = false; + if (A != nullptr && B != nullptr) + { + if (A->val == B->val) + { + res = hasTree(A, B); + } + if (!res) + { + res = isSubStructure(A->left, B); + } + if (!res) + { + res = isSubStructure(A->right, B); + } + } + return res; +} + diff --git a/isNumber.cpp b/isNumber.cpp new file mode 100644 index 0000000..a443ff7 --- /dev/null +++ b/isNumber.cpp @@ -0,0 +1,144 @@ +#include +#include +using namespace std; + + +//如下算法设计实际上失败了,使用指针的方式,可以实现bool值和指针移动,最具有简洁性 +// +// bool flag = false; + +// string Unint(string s) +// { +// while (s[0] >= '0' && s[0] <= '9'){ +// s = s.substr(1); +// } +// return s; +// } + +// string ints(string &s) +// { +// if (s[0] == '+' || s[0] == '-') +// { +// s.substr(1); +// } +// while (s[0] >= '0' && s[0] <= '9'){ +// s.substr(1); +// } +// return s; +// } + +// bool compare_one(string one, string two) +// { +// return one.size() < two.size() ? true : false; +// } + +// bool compare_two(string one, string two) +// { +// return one.size() < two.size() - 1? true : false; +// } + +// string trim(string s) +// { +// if (s.empty()) +// { +// return s; +// } +// s.erase(0,s.find_first_not_of(" ")); +// s.erase(s.find_last_not_of(" ") + 1); +// return s; +// } + +// bool isNumber(string s) +// { +// s = trim(s); +// if (s.empty() || s.find(" ") != s.npos) +// { +// return false; +// } +// string tmp = ints(s); +// string tmp_two; +// bool numeric = compare_two(tmp, s); +// if (tmp[0] == '.') +// { +// tmp = tmp.substr(1); +// tmp_two = Unint(tmp); +// numeric = numeric || compare_one(tmp_two, tmp); +// tmp =tmp_two; +// } +// if (tmp[0] == 'e'|| tmp[0] == 'E') +// { +// tmp_two = tmp.substr(1); +// tmp = ints(tmp_two); +// numeric = numeric && compare_two(tmp, tmp_two); +// } +// return numeric && tmp.empty(); +// } + +int point = 0; + +bool Unint(string s) +{ + int p = point; + while (s[point] >= '0' && s[point] <= '9') + { + point++; + } + return point > p; +} + +bool ints(string s) +{ + int p = point; + if (s[point] == '+' || s[point] == '-') + { + point++; + } + return Unint(s); +} + +string trim(string s) +{ + if (s.empty()) + { + return s; + } + s.erase(0,s.find_first_not_of(" ")); + s.erase(s.find_last_not_of(" ") + 1); + if (s.find(" ") != s.npos) + { + s = ""; + } + return s; +} + + +bool isNumber(string s) +{ + s = trim(s); + if (s.empty()) + { + return false; + } + + bool numeric = ints(s); + + if (s[point] == '.') + { + point++; + numeric = Unint(s) || numeric; + } + if (s[point] == 'e'|| s[point] == 'E') + { + point++; + numeric = numeric && ints(s); + } + return numeric && (point == s.size()); +} + +int main() +{ + string s = "0.8"; + bool one = isNumber(s); + // cout<< s.substr(1); + return 0; +} diff --git a/isNumber.exe b/isNumber.exe new file mode 100644 index 0000000..f771096 Binary files /dev/null and b/isNumber.exe differ diff --git a/isSymmetric.cpp b/isSymmetric.cpp new file mode 100644 index 0000000..6408f98 --- /dev/null +++ b/isSymmetric.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +bool isSymmetric(TreeNode* a, TreeNode* b) +{ + stack s1; + stack s2; + s1.push(a); + s2.push(b); + + bool res = false; + + while (!s1.empty() && !s2.empty()) + { + TreeNode* one = s1.top(); + s1.pop(); + TreeNode* two = s2.top(); + s2.pop(); + + if (one->val != two->val) + { + res = false; + return res; + } + + s1.push(a->left); + s1.push(a->right); + s2.push(b->right); + s2.push(b->left); + } + + res = s1.empty() && s2.empty(); + return res; +} \ No newline at end of file diff --git a/matchCore.cpp b/matchCore.cpp new file mode 100644 index 0000000..b88e267 --- /dev/null +++ b/matchCore.cpp @@ -0,0 +1,105 @@ +#include +#include +using namespace std; + + +bool matchCore(char* str, char* pattern) +{ + if (*str == '\0' && *pattern == '\0') + { + return true; + } + + if (*str != '\0' && *pattern == '\0') + { + return false; + } + + if (*(pattern + 1) == '*') + { + if (*pattern == *str || (*pattern == '.' && *str != '\0')) + { + return matchCore(str + 1, pattern + 2) //能够进来表示,能跟*匹配 + || matchCore(str + 1, pattern) // + || matchCore(str, pattern + 2); // + } + else + { + return matchCore(str, pattern + 2); + } + } + if (*str == *pattern || (*pattern == '.' && *str != '\0')) + { + return matchCore(str + 1, pattern + 1); + } + return false; +} + +bool matches(string s, string p) +{ + if (p.empty()) + { + return s.empty(); + } + + if (p.size() > 1 && p[1] == '*' ) + { + if (s[0] == p[0] || (p[0] == '.' && !s.empty())) + { + return matches(s.substr(1),p); + } + else + { + return matches(s, p.substr(2)); + } + } + if (s[0] == p[0] || (p[0] == '.' && !s.empty())) + { + return matches(s.substr(1), p.substr(1)); + } + return false; +} + + +bool match(char* str, char* pattern) +{ + if (str == nullptr || pattern == nullptr) + { + return false; + } + return matchCore(str, pattern); + +} + +bool isMatch(string s, string p) +{ + if (p.empty()) + { + return s.empty(); + } + + if (p.size() > 1 && p[1] == '*' ) + { + if (s[0] == p[0] || (p[0] == '.' && !s.empty())) + { + return isMatch(s.substr(1),p)||isMatch(s, p.substr(2)); + } + else + { + return isMatch(s, p.substr(2)); + } + } + if (s[0] == p[0] || (p[0] == '.' && !s.empty())) + { + return isMatch(s.substr(1), p.substr(1)); + } + return false; +} + +int main() +{ + string a = "aaaa"; + string b = "a*a"; + bool res = isMatch(a,b); + return 0; +} \ No newline at end of file diff --git a/matchCore.exe b/matchCore.exe new file mode 100644 index 0000000..a9728d8 Binary files /dev/null and b/matchCore.exe differ diff --git a/mergeTwoLists.cpp b/mergeTwoLists.cpp new file mode 100644 index 0000000..1e8e4ac --- /dev/null +++ b/mergeTwoLists.cpp @@ -0,0 +1,57 @@ +#include +#include +using namespace std; + + +struct ListNode { + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { + if (l1 == nullptr) + { + return l2; + } + if (l2 == nullptr) + { + return l1; + } + + ListNode* p_merge; + if (l1->val <= l2->val) + { + p_merge = l1; + p_merge->next = mergeTwoLists(l1->next,l2); + } + else + { + p_merge = l2; + p_merge->next = mergeTwoLists(l1, l2->next); + } + return p_merge; +} + +ListNode* create_node(ListNode*& head, vector& nums) +{ + head = new ListNode(0); + ListNode* p = head; + for (int i = 0; i < nums.size(); i++) + { + ListNode* p2 = new ListNode(nums[i]); + p->next = p2; + p = p2; + } + return head; +} + +int main() +{ + vector nums = {1,2,4}; + vector num2 = {1,3,4}; + ListNode* p1 = create_node(p1, nums); + ListNode* p2 = create_node(p2, nums); + ListNode* p3 = mergeTwoLists(p1,p2); + return 0; +} \ No newline at end of file diff --git a/mergeTwoLists.exe b/mergeTwoLists.exe new file mode 100644 index 0000000..7afa6b6 Binary files /dev/null and b/mergeTwoLists.exe differ diff --git a/mirrorTree.cpp b/mirrorTree.cpp new file mode 100644 index 0000000..1fcb715 --- /dev/null +++ b/mirrorTree.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +/* void swaps(TreeNode* a, TreeNode* b) +{ + TreeNode* tmp = a; + b = a; + b = tmp; +} */ + +TreeNode* mirrorTree(TreeNode* root) { + if (root == nullptr) + { + return root; + } + if (root->left == nullptr && root->right == nullptr) + { + return root; + } + + swap(root->left, root->right); + + if (root->left) + { + mirrorTree(root->left); + } + if (root->right) + { + mirrorTree(root->right); + } + return root; +} + + +TreeNode* mirror(TreeNode* root) +{ + stack s; + s.push(root); + while (!s.empty()) + { + TreeNode* node = s.top(); + s.pop(); + if (node == nullptr) + { + break; + } + swap(node->left, node->right); + s.push(node->left); + s.push(node->right); + } + return root; +} + +TreeNode* buildTree(TreeNode* &root, vector& nums, int lens, int i) +{ + if (i >= lens) + { + return root; + } + root = new TreeNode(nums[i]); + buildTree(root->left, nums, lens, i * 2 + 1); + buildTree(root->right, nums, lens, i * 2 + 2); + return root; +} +// +int main() +{ + vector one = {4,2,7,1,3,6,9}; + TreeNode* root; + buildTree(root, one, one.size(), 0); + mirror(root); + return 0; +} + diff --git a/mirrorTree.exe b/mirrorTree.exe new file mode 100644 index 0000000..7c7e01f Binary files /dev/null and b/mirrorTree.exe differ diff --git a/one/.vscode/c_cpp_properties.json b/one/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..02aa62a --- /dev/null +++ b/one/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "intelliSenseMode": "gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/one/.vscode/launch.json b/one/.vscode/launch.json new file mode 100644 index 0000000..e76a034 --- /dev/null +++ b/one/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", // 閰嶇疆鍚嶇О锛屽皢浼氬湪鍚姩閰嶇疆鐨勪笅鎷夎彍鍗曚腑鏄剧ず + "type": "cppdbg", // 閰嶇疆绫诲瀷锛岃繖閲屽彧鑳戒负cppdbg + "request": "launch", // 璇锋眰閰嶇疆绫诲瀷锛屽彲浠ヤ负launch锛堝惎鍔級鎴朼ttach锛堥檮鍔狅級 + "program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",// 灏嗚杩涜璋冭瘯鐨勭▼搴忕殑璺緞 + "args": [], // 绋嬪簭璋冭瘯鏃朵紶閫掔粰绋嬪簭鐨勫懡浠よ鍙傛暟锛屼竴鑸涓虹┖鍗冲彲 + "stopAtEntry": false, // 璁句负true鏃剁▼搴忓皢鏆傚仠鍦ㄧ▼搴忓叆鍙e锛屼竴鑸缃负false + "cwd": "${workspaceFolder}", // 璋冭瘯绋嬪簭鏃剁殑宸ヤ綔鐩綍锛屼竴鑸负${workspaceFolder}鍗充唬鐮佹墍鍦ㄧ洰褰 + "environment": [], + "externalConsole": true, // 璋冭瘯鏃舵槸鍚︽樉绀烘帶鍒跺彴绐楀彛锛屼竴鑸缃负true鏄剧ず鎺у埗鍙 + "MIMode": "gdb", + "miDebuggerPath": "D:\\VS Code\\mingw64\\bin\\gdb.exe", // miDebugger鐨勮矾寰勶紝娉ㄦ剰杩欓噷瑕佷笌MinGw鐨勮矾寰勫搴 + "preLaunchTask": "g++", // 璋冭瘯浼氳瘽寮濮嬪墠鎵ц鐨勪换鍔★紝涓鑸负缂栬瘧绋嬪簭锛宑++涓篻++, c涓篻cc + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/one/.vscode/settings.json b/one/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/one/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/one/.vscode/tasks.json b/one/.vscode/tasks.json new file mode 100644 index 0000000..6a73db7 --- /dev/null +++ b/one/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "g++", //杩欓噷娉ㄦ剰涓涓嬶紝瑙佷笅鏂 + "command": "D:\\VS Code\\mingw64\\bin\\g++.exe", + "args": [ + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "D:\\VS Code\\mingw64\\bin" + }, + "problemMatcher": [ + "$gcc" + ] + } + ] +} \ No newline at end of file diff --git a/one/buildTree.cpp b/one/buildTree.cpp new file mode 100644 index 0000000..510f728 --- /dev/null +++ b/one/buildTree.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +vector res; + +void buildTree(TreeNode* root, vector& nums, int lens, int i) +{ + if (i >= lens) + { + return; + } + root = new TreeNode(nums[i]); + buildTree(root->left, nums, lens, i << 1 + 1); + buildTree(root->right, nums, lens, i << 1 + 2); +} + + +void inorderTravel(TreeNode* root) +{ + if (root == NULL) + { + return; + } + + if (root->left != NULL) + { + inorderTravel(root->left); + } + + res.push_back(root->val); + + if (root->right != NULL) + { + inorderTravel(root->right); + } +} + +void Trees(TreeNode** root, vector& nums) +{ + int lens = nums.size(); + buildTree(*root, nums, lens, 0); +} + +int main() +{ + vector nums = {1, 2, 3, 4, 5, 6, 7, 8}; + TreeNode* root; + Trees(&root, nums); + return 0; +} \ No newline at end of file diff --git a/one/buildTree.exe b/one/buildTree.exe new file mode 100644 index 0000000..6d4686e Binary files /dev/null and b/one/buildTree.exe differ diff --git a/one/exchange.cpp b/one/exchange.cpp new file mode 100644 index 0000000..466b2e4 --- /dev/null +++ b/one/exchange.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +using namespace std; + +vector exchange(vector& nums) +{ + int lens = nums.size() - 1; + int head, tail = 0, lens; + while (head < tail) + { + while(head < tail && nums[head] & 1) head++; + while(head < tail && !(nums[tail] & 1)) tail--; + if(head < tail) swap(nums[head], nums[tail]); + } + return nums; +} \ No newline at end of file diff --git a/one/getKthFromEnd.cpp b/one/getKthFromEnd.cpp new file mode 100644 index 0000000..2f2e0c6 --- /dev/null +++ b/one/getKthFromEnd.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +struct ListNode { + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +ListNode* getKthFromEnd(ListNode* head, int k) { + if (head == nullptr || k == 0) + { + return head; + } + ListNode* p1 = head; + ListNode* p2 = head; + for (int i = 0; i < k - 1; i++) + { + if (p1->next != nullptr) + { + p1 = p1->next; + } + } + while (p1->next != nullptr) + { + p1 = p1->next; + p2 = p2->next; + } + + return p2; +} \ No newline at end of file diff --git a/one/reverseList.cpp b/one/reverseList.cpp new file mode 100644 index 0000000..6df8692 --- /dev/null +++ b/one/reverseList.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +using namespace std; + +struct ListNode { + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +// ListNode* reverseList(ListNode* head) { +// ListNode* p = head; +// ListNode* p_pre = nullptr; +// ListNode* p_head = nullptr; +// while ( p != nullptr) +// { +// if (p->next == nullptr) +// break; +// ListNode* p_next = p->next; +// p->next = p_pre; +// p_pre = p; +// p = p_next; +// } +// return p; +// } + +ListNode* reverseList(ListNode* head) { + ListNode* p = head; + ListNode* p_pre = nullptr; + ListNode* p_head = nullptr; + while (p != nullptr) + { + if(p->next == nullptr){ + p_head = p; + } + ListNode* p_next = p->next; + p->next = p_pre; + p_pre = p; + p = p_next; + } + return p_head; +} \ No newline at end of file diff --git a/spiralOrder.cpp b/spiralOrder.cpp new file mode 100644 index 0000000..a3e5053 --- /dev/null +++ b/spiralOrder.cpp @@ -0,0 +1,60 @@ +#include +#include +using namespace std; + +vector res; +void printm(vector>& nums, int rows, int cols, int i) +{ + //i能不能被视为第i圈 + int endx = cols - 1 - i; + int endy = rows - 1 - i; + //从左到右 + for (int j = i; j <= endx; j++) + { + res.push_back(nums[i][j]); + } + //右边:从上到下打印 + if (i < endy) + { + for (int j = i + 1; j <= endy; j++) + { + res.push_back(nums[j][endx]); + } + } + //右边:从右到左 + if (i < endx && i < endy) + { + for (int j = endx - 1; j >= i; j--) + { + res.push_back(nums[endy][j]); + } + } + + //从下到上 + if (i < endx && i < endy - 1) + { + for (int j = endy - 1; j > i; j--) + { + res.push_back(nums[j][i]); + } + } +} + + +vector spiralOrder(vector>& matrix) { + int rows = matrix.size(); + int cols = matrix[0].size(); + + if (matrix.empty()) + { + return; + } + + int i = 0; + + while(cols > i * 2 && rows > i * 2){ + printm(matrix, rows, cols, i); + i++; + } + return res; +} diff --git a/substr.cpp b/substr.cpp new file mode 100644 index 0000000..2e3c4bb --- /dev/null +++ b/substr.cpp @@ -0,0 +1,12 @@ +#include +#include +#include + +using namespace std; + +int main() +{ +  string as = "12345asdf"; +  string a = as.substr(0,5); //获得字符串s中从第0位开始的长度为5的字符串 + return 0; +} \ No newline at end of file diff --git "a/\345\221\275\344\273\244\350\241\214.txt" "b/\345\221\275\344\273\244\350\241\214.txt" new file mode 100644 index 0000000..e5d0167 --- /dev/null +++ "b/\345\221\275\344\273\244\350\241\214.txt" @@ -0,0 +1,4 @@ + zmk@zmkdeMacBook-Pro 顐 ~/c++/now_coding 顐 顐 master 顐 git config --global user.name "ZMK112" + zmk@zmkdeMacBook-Pro 顐 ~/c++/now_coding 顐 顐 master 顐 git config --global user.email "1109645606@qq.com" + zmk@zmkdeMacBook-Pro 顐 ~/c++/now_coding 顐 顐 master 顐 git remote add origin git@github.com:ZMK112/AlgorithmCode.git + zmk@zmkdeMacBook-Pro 顐 ~/c++/now_coding 顐 顐 master 顐 git fetch