Skip to content

Commit f0abee8

Browse files
committed
first commit
0 parents  commit f0abee8

39 files changed

+1524
-0
lines changed

Diff for: .vscode/c_cpp_properties.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"D:/Program Files (x86)/CodeBlocks/MinGW/lib/**"
8+
],
9+
"defines": [
10+
"_DEBUG",
11+
"UNICODE",
12+
"_UNICODE"
13+
],
14+
"intelliSenseMode": "msvc-x64"
15+
}
16+
],
17+
"version": 4
18+
}

Diff for: .vscode/launch.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "(gdb) 启动",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "输入程序名称,例如 ${workspaceFolder}/a.exe",
12+
"args": [],
13+
"stopAtEntry": false,
14+
"cwd": "${workspaceFolder}",
15+
"environment": [],
16+
"externalConsole": false,
17+
"MIMode": "gdb",
18+
"miDebuggerPath": "/path/to/gdb",
19+
"setupCommands": [
20+
{
21+
"description": "为 gdb 启用整齐打印",
22+
"text": "-enable-pretty-printing",
23+
"ignoreFailures": true
24+
}
25+
]
26+
}
27+
]
28+
}

Diff for: .vscode/settings.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"files.associations": {
3+
"array": "cpp",
4+
"*.tcc": "cpp",
5+
"cctype": "cpp",
6+
"clocale": "cpp",
7+
"cstdarg": "cpp",
8+
"cstdint": "cpp",
9+
"cstdio": "cpp",
10+
"cstdlib": "cpp",
11+
"cwchar": "cpp",
12+
"cwctype": "cpp",
13+
"unordered_map": "cpp",
14+
"vector": "cpp",
15+
"exception": "cpp",
16+
"fstream": "cpp",
17+
"functional": "cpp",
18+
"initializer_list": "cpp",
19+
"iosfwd": "cpp",
20+
"istream": "cpp",
21+
"limits": "cpp",
22+
"new": "cpp",
23+
"ostream": "cpp",
24+
"sstream": "cpp",
25+
"stdexcept": "cpp",
26+
"streambuf": "cpp",
27+
"tuple": "cpp",
28+
"type_traits": "cpp",
29+
"utility": "cpp",
30+
"typeinfo": "cpp",
31+
"iostream": "cpp"
32+
}
33+
}

Diff for: .vscode/tasks.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "shell",
5+
"label": "g++.exe build active file",
6+
"command": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\g++.exe",
7+
"args": [
8+
"-g",
9+
"${file}",
10+
"-o",
11+
"${fileDirname}\\${fileBasenameNoExtension}.exe"
12+
],
13+
"options": {
14+
"cwd": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin"
15+
}
16+
}
17+
],
18+
"version": "2.0.0"
19+
}

Diff for: 1.两数之和.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @lc app=leetcode.cn id=1 lang=cpp
3+
*
4+
* [1] 两数之和
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public:
10+
vector<int> twoSum(vector<int>& nums, int target) {
11+
vector<int> ans;
12+
unordered_map<int,int> m;
13+
14+
for(int i=0;i<nums.size();i++){
15+
if(m.find(target-nums[i])!=m.end()){
16+
ans.push_back(m[target-nums[i]]);
17+
ans.push_back(i);
18+
return ans;
19+
}
20+
m[nums[i]] = i;
21+
}
22+
return ans;
23+
24+
}
25+
};
26+
// @lc code=end
27+

Diff for: 100.相同的树.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* @lc app=leetcode.cn id=100 lang=cpp
3+
*
4+
* [100] 相同的树
5+
*/
6+
7+
// @lc code=start
8+
9+
// Definition for a binary tree node.
10+
11+
#include<iostream>
12+
13+
using namespace std;
14+
15+
// struct TreeNode {
16+
// int val;
17+
// TreeNode *left;
18+
// TreeNode *right;
19+
// TreeNode(int x) : val(x), left(NULL), right(NULL) {}
20+
// };
21+
22+
class Solution {
23+
public:
24+
bool isSameTree(TreeNode* p, TreeNode* q) {
25+
if(p!=NULL && q==NULL || p==NULL &&q!=NULL)return false;
26+
if(p==NULL && q==NULL)return true;
27+
28+
bool res = p->val == q->val;
29+
if(res && isSameTree(p->left,q->left))
30+
{
31+
if(isSameTree(p->right,q->right)){
32+
return true;
33+
}
34+
}
35+
return false;
36+
}
37+
};
38+
// @lc code=end
39+

Diff for: 107.二叉树的层次遍历-ii.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* @lc app=leetcode.cn id=107 lang=cpp
3+
*
4+
* [107] 二叉树的层次遍历 II
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* Definition for a binary tree node.
10+
* */
11+
12+
#include<iostream>
13+
#include<vector>
14+
#include<queue>
15+
#include<stack>
16+
17+
using namespace std;
18+
// struct TreeNode {
19+
// int val;
20+
// TreeNode *left;
21+
// TreeNode *right;
22+
// TreeNode(int x) : val(x), left(NULL), right(NULL) {}
23+
// };
24+
25+
class Solution {
26+
public:
27+
vector<vector<int>> levelOrderBottom(TreeNode* root) {
28+
vector<vector<int> > vv;
29+
if(root==NULL)return vv;
30+
stack<vector<int> > s;
31+
queue<TreeNode *> q;
32+
q.push(root);
33+
while(!q.empty()){
34+
vector<int> v;
35+
queue<TreeNode *> tree;
36+
while(!q.empty()){
37+
TreeNode * front = q.front();
38+
v.push_back(front->val);
39+
q.pop();
40+
if(front->left!=NULL){
41+
tree.push(front->left);
42+
}
43+
if(front->right!=NULL){
44+
tree.push(front->right);
45+
}
46+
}
47+
s.push(v);
48+
q = tree;
49+
}
50+
51+
while(!s.empty()){
52+
vv.push_back(s.top());
53+
s.pop();
54+
}
55+
return vv;
56+
}
57+
};
58+
// @lc code=end
59+

Diff for: 108.将有序数组转换为二叉搜索树.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @lc app=leetcode.cn id=108 lang=cpp
3+
*
4+
* [108] 将有序数组转换为二叉搜索树
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* Definition for a binary tree node. */
10+
#include<iostream>
11+
#include<vector>
12+
13+
using namespace std;
14+
15+
// struct TreeNode {
16+
// int val;
17+
// TreeNode *left;
18+
// TreeNode *right;
19+
// TreeNode(int x) : val(x), left(NULL), right(NULL) {}
20+
// };
21+
22+
class Solution {
23+
public:
24+
TreeNode* sortedArrayToBST(vector<int>& nums) {
25+
if(nums.empty())return NULL;
26+
vector<int> vector_l(nums.begin(),nums.begin()+nums.size()/2);
27+
vector<int> vector_r(nums.begin()+nums.size()/2+1,nums.end());
28+
29+
TreeNode * root = new TreeNode(nums[nums.size()/2]);
30+
31+
root->left = sortedArrayToBST(vector_l);
32+
root->right = sortedArrayToBST(vector_r);
33+
34+
return root;
35+
}
36+
};
37+
// @lc code=end
38+

Diff for: 110.平衡二叉树.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* @lc app=leetcode.cn id=110 lang=cpp
3+
*
4+
* [110] 平衡二叉树
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* Definition for a binary tree node. */
10+
11+
#include<iostream>
12+
#include<vector>
13+
#include<algorithm>
14+
15+
using namespace std;
16+
17+
// struct TreeNode {
18+
// int val;
19+
// TreeNode *left;
20+
// TreeNode *right;
21+
// TreeNode(int x) : val(x), left(NULL), right(NULL) {}
22+
// };
23+
24+
class Solution {
25+
public:
26+
bool isBalanced(TreeNode* root) {
27+
if(root==NULL)return true;
28+
int lh = height(root->left);
29+
int rh = height(root->right);
30+
return (abs(lh-rh)<=1)&&isBalanced(root->left) && isBalanced(root->right);
31+
}
32+
33+
int height(TreeNode* root){
34+
if(root==NULL)return 0;
35+
36+
int lh = height(root->left);
37+
int rh = height(root->right);
38+
39+
return max(lh,rh) + 1;
40+
}
41+
};
42+
// @lc code=end
43+

Diff for: 112.路径总和.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @lc app=leetcode.cn id=112 lang=cpp
3+
*
4+
* [112] 路径总和
5+
*/
6+
7+
// @lc code=start
8+
9+
// Definition for a binary tree node.
10+
11+
#include<iostream>
12+
13+
using namespace std;
14+
15+
// struct TreeNode {
16+
// int val;
17+
// TreeNode *left;
18+
// TreeNode *right;
19+
// TreeNode(int x) : val(x), left(NULL), right(NULL) {}
20+
// };
21+
class Solution {
22+
public:
23+
bool hasPathSum(TreeNode* root, int sum) {
24+
if(root==NULL){
25+
return false;
26+
}
27+
if(root->left==NULL && root->right==NULL && root->val==sum)return true;
28+
return hasPathSum(root->left,sum-root->val) || hasPathSum(root->right,sum-root->val);
29+
}
30+
};
31+
// @lc code=end
32+

Diff for: 121.买卖股票的最佳时机.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @lc app=leetcode.cn id=121 lang=cpp
3+
*
4+
* [121] 买卖股票的最佳时机
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public:
10+
int maxProfit(vector<int>& prices) {
11+
int max_p=0;
12+
if(prices.size()==0)return max_p;
13+
for(int i=0;i<prices.size()-1;++i)
14+
{
15+
for(int j=i+1;j<prices.size();++j){
16+
if(max_p<prices[j]-prices[i]){
17+
max_p = prices[j]-prices[i];
18+
}
19+
}
20+
}
21+
return max_p;
22+
}
23+
};
24+
// @lc code=end
25+

0 commit comments

Comments
 (0)