Skip to content

Commit 3c602b8

Browse files
committed
fix build error
1 parent 29ddea7 commit 3c602b8

Some content is hidden

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

59 files changed

+105
-145
lines changed

buildcpp.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
cpps = glob.glob("cpp/*.cpp")
5+
errors = []
56
for cpp in cpps:
67
print(cpp)
78
code = '''
@@ -11,12 +12,15 @@
1112
int val;
1213
TreeNode *left;
1314
TreeNode *right;
14-
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
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) {}
1518
};
1619
struct ListNode {
1720
int val;
1821
ListNode *next;
1922
ListNode(int x) : val(x), next(NULL) {}
23+
ListNode(int x, ListNode *next) : val(x), next(next) {}
2024
};
2125
struct RandomListNode {
2226
int label;
@@ -44,23 +48,17 @@ class Employee {
4448
// the id of direct subordinates
4549
vector<int> subordinates;
4650
};
47-
class Node {
48-
public:
49-
int val;
50-
vector<Node*> children;
51-
52-
Node() {}
53-
54-
Node(int _val, vector<Node*> _children) {
55-
val = _val;
56-
children = _children;
57-
}
58-
};
5951
'''
6052
with open(cpp) as f:
6153
code += f.read()
6254
with open("a.cpp", "w") as f:
6355
f.writelines(code)
64-
cmd = "g++ a.cpp -o a.so -shared -fpic -std=c++17"
56+
cmd = "g++ a.cpp -o a.so -shared -fpic -std=c++20"
6557
if 0 != os.system(cmd):
66-
exit(-1)
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/111.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Solution {
2121
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
2222
* };
2323
*/
24-
class Solution {
24+
class Solution2 {
2525
int min = INT_MAX;
2626

2727
public:

cpp/125.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Solution {
2828
return 0;
2929
}
3030
};
31-
class Solution {
31+
class Solution2 {
3232
public:
3333
bool isPalindrome(string s) {
3434
string filtered;

cpp/131.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Solution {
3030
}
3131
};
3232
// dfs.cpp
33-
class Solution {
33+
class Solution2 {
3434
void dfs(int index, string& s, vector<string>& path,
3535
vector<vector<string>>& ret) {
3636
if (index == s.size()) {

cpp/133.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*
2-
// Definition for a Node.
31
class Node {
42
public:
53
int val;
@@ -17,7 +15,6 @@ class Node {
1715
neighbors = _neighbors;
1816
}
1917
};
20-
*/
2118

2219
class Solution {
2320
public:

cpp/138.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*
2-
// Definition for a Node.
31
class Node {
42
public:
53
int val;
@@ -8,11 +6,10 @@ class Node {
86

97
Node(int _val) {
108
val = _val;
11-
next = NULL;
12-
random = NULL;
9+
next = nullptr;
10+
random = nullptr;
1311
}
1412
};
15-
*/
1613
// noExtraSpace.cpp
1714
class Solution {
1815
public:
@@ -36,7 +33,7 @@ class Solution {
3633
}
3734
};
3835
// scanTWice-60ms.cpp
39-
class Solution {
36+
class Solution2 {
4037
public:
4138
RandomListNode* copyRandomList(RandomListNode* head) {
4239
unordered_map<RandomListNode*, int> hash;

cpp/139.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Solution {
1919
}
2020
};
2121
// trie+dp.cpp 3ms
22-
class Solution {
22+
class Solution2 {
2323
struct trie {
2424
trie() : isWord(false) {}
2525
bool isWord;

cpp/144.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
1010
* };
1111
*/
12-
class Solution {
12+
class Solution2 {
1313
public:
1414
vector<int> preorderTraversal(TreeNode* root) {
1515
auto h = TreeNode(0, nullptr, root);

cpp/146.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class LRUCache {
4141
* obj.put(key,value);
4242
*/
4343
// map_hashmap_103ms.cpp
44-
class LRUCache {
44+
class LRUCache2 {
4545
unsigned int capacity;
4646
map<int, int> timemap; // key time,value cache's key
4747
unordered_map<int, pair<int, int>>
4848
hashmap; // key cache's key,value cache's value and time
4949
unsigned int call;
5050

5151
public:
52-
LRUCache(int capacity) {
52+
LRUCache2(int capacity) {
5353
this->capacity = capacity;
5454
call = 0;
5555
}

cpp/148.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Solution {
4949
* ListNode(int x) : val(x), next(NULL) {}
5050
* };
5151
*/
52-
class Solution {
52+
class Solution2 {
5353
pair<ListNode *, ListNode *> helper(ListNode *head) {
5454
if (!head)
5555
return {nullptr, nullptr};

0 commit comments

Comments
 (0)