-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
200 changed files
with
3,125 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import re | ||
|
||
def replace_or_add_header(file_path, old_header_start, old_header_end, new_header): | ||
with open(file_path, 'r', encoding='utf-8') as f: | ||
content = f.read() | ||
|
||
# Check if the new header already exists | ||
if new_header in content: | ||
print(f"New header already exists in {file_path}, skipping.") | ||
return | ||
|
||
# Define the regex pattern for the old header | ||
pattern = re.compile(rf"{old_header_start}.*?{old_header_end}", re.DOTALL) | ||
|
||
# Check if the old header exists | ||
if pattern.search(content): | ||
# Replace the old header with the new header | ||
new_content = pattern.sub(new_header, content) | ||
print(f"Replaced old header in {file_path}") | ||
else: | ||
# Add the new header if no old header found | ||
new_content = new_header + '\n' + content | ||
print(f"Added new header to {file_path}") | ||
|
||
# Write the new content back to the file | ||
with open(file_path, 'w', encoding='utf-8') as f: | ||
f.write(new_content) | ||
|
||
def add_or_replace_header_in_directory(directory_path, old_header_start, old_header_end, new_header, file_extensions=['.h', '.cc']): | ||
for root, _, files in os.walk(directory_path): | ||
for file_name in files: | ||
if any(file_name.endswith(ext) for ext in file_extensions): | ||
file_path = os.path.join(root, file_name) | ||
replace_or_add_header(file_path, old_header_start, old_header_end, new_header) | ||
|
||
# Old header delimiters | ||
old_header_start = "//=====================================================================" | ||
old_header_end = "//=====================================================================" | ||
|
||
# New header content | ||
new_header = """\ | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// Authors: liubang ([email protected]) | ||
""" | ||
|
||
directory_path = './' | ||
|
||
add_or_replace_header_in_directory(directory_path, old_header_start, old_header_end, new_header) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// list.h - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:18 | ||
// Last Modified: 2023/11/30 23:18 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// tree.h - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:18 | ||
// Last Modified: 2023/11/30 23:18 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// uf.h - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:18 | ||
// Last Modified: 2023/11/30 23:18 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
/* | ||
* union-find | ||
*/ | ||
namespace leetcode { | ||
namespace uf { | ||
namespace leetcode::uf { | ||
|
||
class UnionFind { | ||
public: | ||
|
@@ -83,5 +90,4 @@ class UnionFind { | |
std::vector<int> parent_; | ||
}; | ||
|
||
} // namespace uf | ||
} // namespace leetcode | ||
} // namespace leetcode::uf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 101.symmetric-tree.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/04/15 17:45 | ||
// Last Modified: 2023/04/15 17:45 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include "tree.h" | ||
#include <memory> | ||
#include <string> | ||
|
18 changes: 13 additions & 5 deletions
18
src/1010.pairs-of-songs-with-total-durations-divisible-by-60.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1010.pairs-of-songs-with-total-durations-divisible-by-60.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/05/07 14:23 | ||
// Last Modified: 2023/05/07 14:23 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
|
||
#include <unordered_map> | ||
#include <vector> | ||
|
18 changes: 13 additions & 5 deletions
18
src/1016.binary-string-with-substrings-representing-1-to-n.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1016.binary-string-with-substrings-representing-1-to-n.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/05/11 01:12 | ||
// Last Modified: 2023/05/11 01:12 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
|
||
#include <bitset> | ||
#include <string> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1019.next-greater-node-in-linked-list.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:08 | ||
// Last Modified: 2023/11/30 23:08 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include <stack> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 102.binary-tree-level-order-traversal.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/04/15 17:45 | ||
// Last Modified: 2023/04/15 17:45 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include "tree.h" | ||
#include <memory> | ||
#include <queue> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1023.camelcase-matching.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:08 | ||
// Last Modified: 2023/11/30 23:08 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1027.longest-arithmetic-subsequence.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/04/23 00:28 | ||
// Last Modified: 2023/04/23 00:28 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include <vector> | ||
|
||
#include <gtest/gtest.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1031.maximum-sum-of-two-non-overlapping-subarrays.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/04/26 01:22 | ||
// Last Modified: 2023/04/26 01:22 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
|
||
#include <gtest/gtest.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
//===================================================================== | ||
// Copyright (c) 2024 The Authors. All rights reserved. | ||
// | ||
// 1035.uncrossed-lines.cc - | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// Created by liubang on 2023/11/30 23:08 | ||
// Last Modified: 2023/11/30 23:08 | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//===================================================================== | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Authors: liubang ([email protected]) | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <vector> | ||
|
Oops, something went wrong.