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

+13-15
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

+1-1
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

+1-1
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

+1-1
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

-3
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

+3-6
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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};

cpp/152.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Solution {
1515
}
1616
};
1717
// singleScanConstantSpace-8ms.cpp
18-
class Solution {
18+
class Solution2 {
1919
public:
2020
int maxProduct(vector<int> &nums) {
2121
auto maxPro = nums[0], minPro = nums[0], ret = nums[0];

cpp/17.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ vector<string> Solution::letter = {"", "", "abc", "def", "ghi",
2525
"jkl", "mno", "pqrs", "tuv", "wxyz"};
2626

2727
string keymap[] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
28-
class Solution {
28+
class Solution2 {
2929
vector<string> combine(vector<string>& a, string& b) {
3030
vector<string> res;
3131
for (auto& i : a) {

cpp/206.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Solution {
3131
* ListNode(int x) : val(x), next(NULL) {}
3232
* };
3333
*/
34-
class Solution {
34+
class Solution2 {
3535
ListNode *impl(ListNode *pre, ListNode *now) {
3636
ListNode *next = now->next;
3737
now->next = pre;

cpp/211.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WordDictionary {
3939
* bool param_2 = obj.search(word);
4040
*/
4141
// trie.cpp
42-
class WordDictionary {
42+
class WordDictionary2 {
4343
struct trie {
4444
trie() : isWord(false) { memset(this->children, 0, sizeof(children)); }
4545
bool isWord;
@@ -48,7 +48,7 @@ class WordDictionary {
4848

4949
public:
5050
/** Initialize your data structure here. */
51-
WordDictionary() {}
51+
WordDictionary2() {}
5252

5353
/** Adds a word into the data structure. */
5454
void addWord(string word) {

cpp/222.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Solution {
3838
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
3939
* };
4040
*/
41-
class Solution {
41+
class Solution2 {
4242
public:
4343
int countNodes(TreeNode *root) {
4444
int Deep = 0, result = 0;

cpp/264.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Solution {
1717
}
1818
};
1919
// set.cpp
20-
class Solution {
20+
class Solution2 {
2121
public:
2222
int nthUglyNumber(int n) {
2323
set<long long int> s;

cpp/307.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class NumArray {
3838
* int param_2 = obj->sumRange(i,j);
3939
*/
4040

41-
class NumArray {
41+
class NumArray2 {
4242
// Runtime: 184 ms, faster than 13.56% of C++ online submissions for Range Sum
4343
// Query - Mutable. Memory Usage: 20 MB, less than 23.38% of C++ online
4444
// submissions for Range Sum Query - Mutable.
@@ -62,7 +62,7 @@ class NumArray {
6262
}
6363

6464
public:
65-
NumArray(vector<int> &nums) : m_nums(nums) {
65+
NumArray2(vector<int> &nums) : m_nums(nums) {
6666
int len = nums.size();
6767
if (len == 0)
6868
return;

cpp/313.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Solution {
2626
}
2727
};
2828
// priority_queue.cpp
29-
class Solution {
29+
class Solution2 {
3030
public:
3131
int nthSuperUglyNumber(int n, vector<int> &primes) {
3232
priority_queue<long long int, vector<long long int>, greater<int>> pq;
@@ -47,7 +47,7 @@ class Solution {
4747
}
4848
};
4949
// usingVector.cpp
50-
class Solution {
50+
class Solution3 {
5151
public:
5252
int nthSuperUglyNumber(int n, vector<int> &primes) {
5353
vector<int> index(primes.size(), 0), cache(primes), res(n, 1);

cpp/318.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Solution {
1717
}
1818
};
1919
// lower-efficient.cpp
20-
class Solution {
20+
class Solution2 {
2121
public:
2222
int maxProduct(vector<string> &words) {
2323
int len = 0;

cpp/331.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Solution {
1515
}
1616
};
1717
// dfs+stringstream.cpp
18-
class Solution {
18+
class Solution2 {
1919
bool dfs(vector<string> &arr, int &i) {
2020
if (i >= arr.size())
2121
return false;

cpp/336.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Solution { // Time Limit Exceeded
1212
return ret;
1313
}
1414
};
15-
class Solution {
15+
class Solution2 {
1616
// Runtime: 152 ms, faster than 94.79% of C++ online submissions for
1717
// Palindrome Pairs. Memory Usage: 28.2 MB, less than 94.95% of C++ online
1818
// submissions for Palindrome Pairs.

cpp/347.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Solution {
2020
}
2121
};
2222
// hashmap+heap+19ms.cpp
23-
class Solution {
23+
class Solution2 {
2424
public:
2525
vector<int> topKFrequent(vector<int> &nums, int k) {
2626
unordered_map<int, int> hashmap;
@@ -46,7 +46,7 @@ class Solution {
4646
}
4747
};
4848
// hashmap+multimap+22ms.cpp
49-
class Solution {
49+
class Solution3 {
5050
public:
5151
vector<int> topKFrequent(vector<int> &nums, int k) {
5252
unordered_map<int, int> hashmap;

cpp/36.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Solution {
2828
}
2929
};
3030
// timeO81_spaceO243.cpp
31-
class Solution {
31+
class Solution2 {
3232
public:
3333
bool isValidSudoku(vector<vector<char>>& board) {
3434
int ver[9][9] = {}, hor[9][9] = {}, chunk[9][9] = {};

cpp/367.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Solution {
1313
}
1414
};
1515
// 2-0ms.cpp
16-
class Solution {
16+
class Solution2 {
1717
public:
1818
bool isPerfectSquare(int num) {
1919
int i = 1, j = num;

cpp/378.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Solution {
3131
}
3232
};
3333
// sort.cpp
34-
class Solution {
34+
class Solution2 {
3535
public:
3636
int kthSmallest(vector<vector<int>> &matrix, int k) {
3737
multiset<int> res;
@@ -43,7 +43,7 @@ class Solution {
4343
return *it;
4444
}
4545
};
46-
class Solution2 {
46+
class Solution3 {
4747
public:
4848
int kthSmallest(vector<vector<int>> &matrix, int k) {
4949
vector<int> res;

0 commit comments

Comments
 (0)