Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liubang committed Jun 29, 2024
1 parent c153c1e commit bae0b45
Show file tree
Hide file tree
Showing 200 changed files with 3,125 additions and 209 deletions.
62 changes: 62 additions & 0 deletions header.py
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)
18 changes: 13 additions & 5 deletions include/list.h
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>
Expand Down
18 changes: 13 additions & 5 deletions include/tree.h
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>
Expand Down
24 changes: 15 additions & 9 deletions include/uf.h
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:
Expand Down Expand Up @@ -83,5 +90,4 @@ class UnionFind {
std::vector<int> parent_;
};

} // namespace uf
} // namespace leetcode
} // namespace leetcode::uf
16 changes: 16 additions & 0 deletions src/1006.clumsy-factorial.cc
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 {
Expand Down
18 changes: 13 additions & 5 deletions src/101.symmetric-tree.cc
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>
Expand Down
18 changes: 13 additions & 5 deletions src/1010.pairs-of-songs-with-total-durations-divisible-by-60.cc
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>
Expand Down
18 changes: 13 additions & 5 deletions src/1016.binary-string-with-substrings-representing-1-to-n.cc
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>
Expand Down
18 changes: 13 additions & 5 deletions src/1019.next-greater-node-in-linked-list.cc
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>

Expand Down
18 changes: 13 additions & 5 deletions src/102.binary-tree-level-order-traversal.cc
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>
Expand Down
18 changes: 13 additions & 5 deletions src/1023.camelcase-matching.cc
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>

Expand Down
18 changes: 13 additions & 5 deletions src/1027.longest-arithmetic-subsequence.cc
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>
Expand Down
18 changes: 13 additions & 5 deletions src/1031.maximum-sum-of-two-non-overlapping-subarrays.cc
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>

Expand Down
18 changes: 13 additions & 5 deletions src/1035.uncrossed-lines.cc
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>
Expand Down
Loading

0 comments on commit bae0b45

Please sign in to comment.