-
Notifications
You must be signed in to change notification settings - Fork 0
Java #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Java #2
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6170bb9
创建code文件夹,避免vscode配置文件干扰
ZMK112 fb49587
将mac的二叉树代码同步
ZMK112 3c776da
提交编辑的命令行
ZMK112 f6204a5
对于树操作较为完整的版本,添加buildTree.cpp
ZMK112 c10e6f2
3/30增加了结点删除和有限状态机mathCore内容
ZMK112 2d9807e
isnumber部分未完成
ZMK112 6070000
isnumber增加部分
ZMK112 45f8275
isNumber修改之后提交
ZMK112 5e537ed
4/2第一次提交,完成一些基本的题目
ZMK112 3d01476
使用栈进行递归操作
ZMK112 18e194b
测试提交
ZMK112 b95149e
增加栈方式实现的对称二叉树代码
ZMK112 a04f4f4
测试
ZMK112 e29d016
Merge branch 'one_branch' of https://github.com/ZMK112/AlgorithmCode ...
ZMK112 14266b8
完整堆栈方式实现镜像
ZMK112 050f7a1
提交前30题
ZMK112 075b487
java code
ZMK112 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions
AlgorithmCode
Submodule AlgorithmCode
added at
7f0f0f
35 changes: 35 additions & 0 deletions
MinStack.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <stack> | ||
| using namespace std; | ||
|
|
||
| stack<int> datas; | ||
| stack<int> 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(); | ||
| } |
60 changes: 60 additions & 0 deletions
buildTree.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include <iostream> | ||
| #include <string.h> | ||
| #include <vector> | ||
| 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<int>& 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<int>& 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<int>& nums) | ||
| { | ||
| int lens = nums.size(); | ||
| buildTree(root, nums, lens, 0); | ||
| return root; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| vector<int> res; | ||
| vector<int> nums = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| TreeNode* root; | ||
| root = Trees(root, nums); | ||
| inorderTravel(root, res); | ||
| return 0; | ||
| } | ||
|
|
Binary file added
buildTree.exe
Binary file not shown.
189 changes: 189 additions & 0 deletions
code/LCOF.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| #include <string.h> | ||
| #include <vector> | ||
| #include <iostream> | ||
| #include <algorithm> | ||
| #include <math.h> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int findRepeatNumber(vector<int>& 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<int>& nums) | ||
| { | ||
| unordered_set<int> dup(nums.begin(), nums.end()); | ||
| if (dup.size() != nums.size()){ | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool containsDuplicate(vector<int>& nums) | ||
| { | ||
| int lens = nums.size(); | ||
| unordered_map<int,int> 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<vector<int>>& 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<vector<int>> nums = {{-5}}; | ||
| // findNumberIn2DArray(nums,-5); | ||
| replaceSpace("We are happy."); | ||
| return 0; | ||
| } |
Binary file added
code/LCOF.exe
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.