Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
ZMK112 wants to merge 17 commits into master
base: master
Choose a base branch
Loading
from java
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6170bb9
创建code文件夹,避免vscode配置文件干扰
ZMK112 Mar 29, 2020
fb49587
将mac的二叉树代码同步
ZMK112 Mar 29, 2020
3c776da
提交编辑的命令行
ZMK112 Mar 29, 2020
f6204a5
对于树操作较为完整的版本,添加buildTree.cpp
ZMK112 Mar 29, 2020
c10e6f2
3/30增加了结点删除和有限状态机mathCore内容
ZMK112 Mar 30, 2020
2d9807e
isnumber部分未完成
ZMK112 Mar 30, 2020
6070000
isnumber增加部分
ZMK112 Mar 30, 2020
45f8275
isNumber修改之后提交
ZMK112 Apr 1, 2020
5e537ed
4/2第一次提交,完成一些基本的题目
ZMK112 Apr 2, 2020
3d01476
使用栈进行递归操作
ZMK112 Apr 2, 2020
18e194b
测试提交
ZMK112 Apr 2, 2020
b95149e
增加栈方式实现的对称二叉树代码
ZMK112 Apr 2, 2020
a04f4f4
测试
ZMK112 Apr 3, 2020
e29d016
Merge branch 'one_branch' of https://github.com/ZMK112/AlgorithmCode ...
ZMK112 Apr 3, 2020
14266b8
完整堆栈方式实现镜像
ZMK112 Apr 3, 2020
050f7a1
提交前30题
ZMK112 Apr 3, 2020
075b487
java code
ZMK112 Apr 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
View file Open in desktop
Binary file not shown.
1 change: 1 addition & 0 deletions AlgorithmCode
Open in desktop
Submodule AlgorithmCode added at 7f0f0f
35 changes: 35 additions & 0 deletions MinStack.cpp
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
Binary file not shown.
189 changes: 189 additions & 0 deletions code/LCOF.cpp
View file Open in desktop
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
View file Open in desktop
Binary file not shown.
Loading

AltStyle によって変換されたページ (->オリジナル) /