Skip to content

Commit 215e67d

Browse files
committed
Master
1 parent 727c0d7 commit 215e67d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2100
-0
lines changed

.vscode/c_cpp_properties.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"macFrameworkPath": [
10+
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
11+
],
12+
"compilerPath": "/usr/bin/clang",
13+
"cStandard": "c17",
14+
"cppStandard": "c++17",
15+
"intelliSenseMode": "macos-clang-arm64"
16+
}
17+
],
18+
"version": 4
19+
}

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "C/C++: g++ 生成和调试活动文件",
5+
"type": "cppdbg",
6+
"request": "launch",
7+
"program": "${fileDirname}/${fileBasenameNoExtension}",
8+
"args": [],
9+
"stopAtEntry": false,
10+
"cwd": "${fileDirname}",
11+
"environment": [],
12+
"externalConsole": false,
13+
"MIMode": "lldb",
14+
"preLaunchTask": "C/C++: g++ 生成活动文件"
15+
}
16+
],
17+
"version": "2.0.0"
18+
}

.vscode/tasks.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: g++ 生成活动文件",
6+
"command": "/usr/bin/g++",
7+
"args": [
8+
"-fdiagnostics-color=always",
9+
"-std=c++11",
10+
"-g",
11+
"${file}",
12+
"-o",
13+
"${fileDirname}/${fileBasenameNoExtension}"
14+
],
15+
"options": {
16+
"cwd": "${fileDirname}"
17+
},
18+
"problemMatcher": [
19+
"$gcc"
20+
],
21+
"group": {
22+
"kind": "build",
23+
"isDefault": true
24+
},
25+
"detail": "调试器生成的任务。"
26+
}
27+
],
28+
"version": "2.0.0"
29+
}

NumMatrix.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
#include<vector>
3+
using namespace std;
4+
5+
class NumMatrix {
6+
public:
7+
NumMatrix(vector<vector<int>>& matrix) {
8+
int m = matrix.size(), n = matrix[0].size();
9+
nums = vector<vector<int>> (m, vector<int>(n, 0));
10+
for(int i = 0; i < m; ++i){
11+
for(int j = 0; j < n; ++j){
12+
if(i == 0 && j == 0){
13+
nums[i][j] = matrix[i][j];
14+
}else if(i == 0){
15+
nums[i][j] = nums[i][j - 1] + matrix[i][j];
16+
}else if(j == 0){
17+
nums[i][j] = nums[i - 1][j] + matrix[i][j];
18+
}else{
19+
nums[i][j] = nums[i - 1][j] + nums[i][j - 1] - nums[i - 1][j - 1] + matrix[i][j];
20+
}
21+
}
22+
}
23+
}
24+
25+
int sumRegion(int row1, int col1, int row2, int col2) {
26+
//cout << "row2 " << row2 << " col2 " << col2 << " row1 " << row1 << " col1 " << col1 << endl;
27+
if(col1 == 0 && row1 == 0)
28+
return nums[row2][col2];
29+
else if(col1 == 0)
30+
return nums[row2][col2] - nums[row1 - 1][col2];
31+
else if(row1 == 0)
32+
return nums[row2][col2] - nums[row2][col1 - 1];
33+
else
34+
return nums[row2][col2] - nums[row1 - 1][col2] - nums[row2][col1 - 1] + nums[row1 - 1][col1 - 1];
35+
}
36+
37+
private:
38+
vector<vector<int>> nums;
39+
};

a.out

-8.39 KB
Binary file not shown.

binaryTreePaths_257.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<vector>
2+
#include<iostream>
3+
#include<string>
4+
using namespace std;
5+
6+
struct TreeNode {
7+
int val;
8+
TreeNode *left;
9+
TreeNode *right;
10+
TreeNode() : val(0), left(nullptr), right(nullptr) {}
11+
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
12+
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
13+
};
14+
15+
class Solution {
16+
public:
17+
void dfs(TreeNode* root, vector<string>& res, string str){
18+
str.append(to_string(root->val));
19+
if(!root->left && !root->right){
20+
res.emplace_back(str);
21+
return;
22+
}else{
23+
str += "->";
24+
}
25+
if(root->left)
26+
dfs(root->left, res, str);
27+
if(root->right)
28+
dfs(root->right, res, str);
29+
30+
}
31+
32+
vector<string> binaryTreePaths(TreeNode* root) {
33+
vector<string> res;
34+
if(!root)
35+
return res;
36+
dfs(root, res, string());
37+
return res;
38+
}
39+
};

canCompleteCircuit

50.9 KB
Binary file not shown.

canCompleteCircuit.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<iostream>
2+
#include<vector>
3+
4+
using namespace std;
5+
6+
class Solution {
7+
public:
8+
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
9+
int start = 0, n = gas.size();
10+
while (start < n)
11+
{
12+
int gasSum = 0, costSum = 0;
13+
int index = 0;
14+
int cnt = 0;
15+
while(cnt < n){
16+
index = (start+cnt) % n;
17+
gasSum += gas[index], costSum += cost[index];
18+
if(gasSum < costSum){
19+
break;
20+
}
21+
cnt++;
22+
}
23+
24+
if(index == start)
25+
return start;
26+
else{
27+
start = index + cnt + 1;
28+
}
29+
cout << start << endl;
30+
}
31+
return -1;
32+
}
33+
};
34+
35+
int main(){
36+
vector<int> gas{1,2,3,4,5}, cost{3,4,5,1,2};
37+
Solution solve;
38+
int res = solve.canCompleteCircuit(gas, cost);
39+
cout << res << endl;
40+
return 0;
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.apple.xcode.dsym.canCompleteCircuit</string>
9+
<key>CFBundleInfoDictionaryVersion</key>
10+
<string>6.0</string>
11+
<key>CFBundlePackageType</key>
12+
<string>dSYM</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
</dict>
20+
</plist>
Binary file not shown.

0 commit comments

Comments
 (0)