Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file not shown.
1 change: 1 addition & 0 deletions AlgorithmCode
Submodule AlgorithmCode added at 7f0f0f
35 changes: 35 additions & 0 deletions MinStack.cpp
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
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
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.
Loading