(hopefully) useful code snippets for LeetCode.
file | description |
---|---|
modular_arithmetic.hpp | MODULO is fixed, which is enough for LeetCode. |
number_utils.hpp | |
varadic_numeric.hpp | |
sorted_utils.hpp | |
binary_tree.hpp | |
linked_list.hpp | |
graph.hpp | with the help of GPT-4 |
string_utils.hpp | with the help of GPT-4 |
monotonic_stack.hpp | |
dominant_tracker.hpp | LeetCode 2780 |
segment_tree.hpp | adapted from https://oi-wiki.org/ds/seg/ |
sliding_window.hpp | with the help of GPT-4 |
interval.hpp | Initially, I aimed for a simplified interval tree, but it turned out differently. Although it's not thoroughly tested and might have some bugs, I managed to use it successfully to solve LeetCode 218's Skyline Problem. Check out the solution here: LeetCode Submission. |
disjoint_set.hpp | with the help of GPT-4 |
big_integer.hpp | with the help of GPT-4 |
To incorporate snippets
into your C++ project, you can use CMake's FetchContent
module as shown below:
cmake_minimum_required(VERSION 3.11)
project(YourProject)
include(FetchContent)
FetchContent_Declare(
snippets
GIT_REPOSITORY https://github.com/hesic73/snippets.git
GIT_TAG main # or any specific tag/version you prefer
)
FetchContent_MakeAvailable(snippets)
add_executable(YourApplication ...)
target_link_libraries(YourApplication PRIVATE snippets)
You can then include the desired header files from snippets
directly in your project's source files:
#include <iostream>
#include "big_integer.h"
int main() {
auto a = hsc_snippets::BigInteger::factorial(100);
auto b = hsc_snippets::BigInteger::pow(hsc_snippets::BigInteger::from_integer(3), 100);
std::cout << a.to_string() << std::endl;
std::cout << b.to_string() << std::endl;
}
The test appears in this manner:
mkdir -p build
cd build
cmake ..
cmake --build . --config Release
ctest -V -C Release