Skip to content

Commit 8f5ddea

Browse files
authored
Merge pull request #1 from HONGJICAI/workflows
Add CI for cpp by Github Actions
2 parents 7170dde + bbc9da7 commit 8f5ddea

File tree

1,062 files changed

+15305
-12832
lines changed

Some content is hidden

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

1,062 files changed

+15305
-12832
lines changed

.github/workflows/ci-cpp.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: C/C++ CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Setup Python
17+
uses: actions/[email protected]
18+
- name: make
19+
run: python buildcpp.py

README.md

Lines changed: 1017 additions & 0 deletions
Large diffs are not rendered by default.

buildcpp.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import glob
2+
import os
3+
4+
cpps = glob.glob("cpp/*.cpp")
5+
errors = []
6+
for cpp in cpps:
7+
print(cpp)
8+
code = '''
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
struct TreeNode {
12+
int val;
13+
TreeNode *left;
14+
TreeNode *right;
15+
TreeNode() : val(0), left(nullptr), right(nullptr) {}
16+
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
17+
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
18+
};
19+
struct ListNode {
20+
int val;
21+
ListNode *next;
22+
ListNode(int x) : val(x), next(NULL) {}
23+
ListNode(int x, ListNode *next) : val(x), next(next) {}
24+
};
25+
struct RandomListNode {
26+
int label;
27+
RandomListNode *next, *random;
28+
RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
29+
};
30+
struct Interval {
31+
int start;
32+
int end;
33+
Interval() : start(0), end(0) {}
34+
Interval(int s, int e) : start(s), end(e) {}
35+
};
36+
struct TreeLinkNode {
37+
int val;
38+
TreeLinkNode *left, *right, *next;
39+
TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
40+
};
41+
class Employee {
42+
public:
43+
// It's the unique ID of each node.
44+
// unique id of this employee
45+
int id;
46+
// the importance value of this employee
47+
int importance;
48+
// the id of direct subordinates
49+
vector<int> subordinates;
50+
};
51+
'''
52+
with open(cpp) as f:
53+
code += f.read()
54+
with open("a.cpp", "w") as f:
55+
f.writelines(code)
56+
cmd = "g++ a.cpp -o a.so -shared -fpic -std=c++20"
57+
if 0 != os.system(cmd):
58+
errors.append(cpp)
59+
if len(errors) > 0:
60+
print("Errors in the following files:")
61+
for error in errors:
62+
print(error)
63+
exit(1)
64+
print("All files compiled successfully.")

cpp/.clang-format

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
---
4+
Language: Cpp
5+
# Force pointers to the type for C++.
6+
AccessModifierOffset: -4
7+
DerivePointerAlignment: false
8+
PointerAlignment: Left

cpp/1.TwoSum.cpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

cpp/1.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
vector<int> twoSum(vector<int>& nums, int target) {
4+
unordered_map<int, int> map;
5+
for (int i = 0; i < nums.size(); ++i) {
6+
if (auto it = map.find(target - nums[i]); it != map.end())
7+
return {it->second, i};
8+
map[nums[i]] = i;
9+
}
10+
return {};
11+
}
12+
};

cpp/100.SameTree/recursion-3ms.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

cpp/100.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
bool isSameTree(TreeNode *p, TreeNode *q) {
13+
if (p == nullptr || q == nullptr)
14+
return p == q;
15+
return p->val == q->val && isSameTree(p->left, q->left) &&
16+
isSameTree(p->right, q->right);
17+
}
18+
};

cpp/1002.FindCommonCharacters.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

cpp/1002.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution { // 8ms 99.37%
2+
public:
3+
vector<string> commonChars(vector<string> &A) {
4+
vector<int> arr(26, numeric_limits<int>::max());
5+
vector<string> res;
6+
for (auto &s : A) {
7+
array<int, 26> cnt = {};
8+
for (auto c : s)
9+
++cnt[c - 'a'];
10+
for (auto i = 0; i < 26; ++i)
11+
arr[i] = min(arr[i], cnt[i]);
12+
}
13+
for (auto i = 0; i < 26; ++i)
14+
while (arr[i] != numeric_limits<int>::max() && arr[i]-- > 0)
15+
res.push_back(string(1, i + 'a'));
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)