Skip to content

Commit 2b2a259

Browse files
committed
format filename
1 parent 944fd0c commit 2b2a259

File tree

1,042 files changed

+15361
-12820
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,042 files changed

+15361
-12820
lines changed

README.md

+1,619
Large diffs are not rendered by default.

cpp/1.TwoSum.cpp

-12
This file was deleted.

cpp/1.cpp

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

-16
This file was deleted.

cpp/100.cpp

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

cpp/1002.FindCommonCharacters.cpp

-18
This file was deleted.

cpp/1002.cpp

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

cpp/1008.ConstructBinarySearchTreeFromPreorderTraversal.cpp

-36
This file was deleted.

cpp/1008.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
// Runtime: 4 ms, faster than 96.40% of C++ online submissions for Construct
12+
// Binary Search Tree from Preorder Traversal. Memory Usage: 8.7 MB, less
13+
// than 97.42% of C++ online submissions for Construct Binary Search Tree from
14+
// Preorder Traversal.
15+
public:
16+
TreeNode *bstFromPreorder(vector<int> &preorder) {
17+
if (not preorder.size())
18+
return nullptr;
19+
auto r = new TreeNode(preorder[0]);
20+
auto now = r;
21+
vector<TreeNode *> st;
22+
for (int i = 1; i < preorder.size(); ++i) {
23+
auto t = preorder[i];
24+
if (t < now->val) {
25+
st.push_back(now);
26+
now = now->left = new TreeNode(t);
27+
} else {
28+
while (st.size() && t > st.back()->val) {
29+
now = st.back();
30+
st.pop_back();
31+
}
32+
now = now->right = new TreeNode(t);
33+
}
34+
}
35+
return r;
36+
}
37+
};

cpp/1009.ComplementofBase10Integer.cpp

-13
This file was deleted.

cpp/1009.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution { // 0ms iteration
2+
public:
3+
int bitwiseComplement(int N) {
4+
if (!N)
5+
return 1;
6+
int res = 0, time = 0;
7+
while (N) {
8+
res += (!(N & 1)) << time++;
9+
N >>= 1;
10+
}
11+
return res;
12+
}
13+
};

cpp/101.SymmetricTree/iteration.cpp

-35
This file was deleted.

cpp/101.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// iteration.cpp
2+
/**
3+
* Definition for a binary tree node.
4+
* struct TreeNode {
5+
* int val;
6+
* TreeNode *left;
7+
* TreeNode *right;
8+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
bool isSymmetric(TreeNode *root) {
14+
if (root == NULL)
15+
return 1;
16+
queue<TreeNode *> qe1, qe2;
17+
qe1.push(root->left);
18+
qe2.push(root->right);
19+
while (!qe1.empty() && !qe2.empty()) {
20+
TreeNode *r1 = qe1.front();
21+
TreeNode *r2 = qe2.front();
22+
qe1.pop();
23+
qe2.pop();
24+
if (r1 && r2) {
25+
if (r1->val != r2->val)
26+
return 0;
27+
qe1.push(r1->left);
28+
qe1.push(r1->right);
29+
qe2.push(r2->right);
30+
qe2.push(r2->left);
31+
} else if (r1 != r2)
32+
return 0;
33+
}
34+
return 1;
35+
}
36+
};

cpp/102.BinaryTreeLevelOrderTraversal/preOrderReversion-3ms.cpp

-25
This file was deleted.

cpp/102.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// preOrderReversion-3ms.cpp
2+
/**
3+
* Definition for a binary tree node.
4+
* struct TreeNode {
5+
* int val;
6+
* TreeNode *left;
7+
* TreeNode *right;
8+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
vector<vector<int>> levelOrder(TreeNode *root) {
14+
vector<vector<int>> result;
15+
preOrder(0, root, result);
16+
return result;
17+
}
18+
void preOrder(int i, TreeNode *root, vector<vector<int>> &nums) {
19+
if (root == NULL)
20+
return;
21+
if (nums.size() == i)
22+
nums.push_back(vector<int>());
23+
nums[i].push_back(root->val);
24+
preOrder(i + 1, root->left, nums);
25+
preOrder(i + 1, root->right, nums);
26+
}
27+
};

cpp/1021.RemoveOutermostParentheses.cpp

-14
This file was deleted.

cpp/1021.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution { // Runtime: 4 ms, faster than 97.26% of C++ online submissions
2+
// for Remove Outermost Parentheses.
3+
public:
4+
string removeOuterParentheses(string S) {
5+
string res;
6+
int opened = 0;
7+
for (char c : S) {
8+
if (c == '(' && opened++)
9+
res += c;
10+
else if (c == ')' && --opened)
11+
res += c;
12+
}
13+
return res;
14+
}
15+
};

cpp/1022.SumofRootToLeafBinaryNumbers.cpp

-18
This file was deleted.

0 commit comments

Comments
 (0)