https://github.com/hesic73/snippets
A bunch of C++ code snippets for tackling LeetCode problems
https://github.com/hesic73/snippets
c-plus-plus cplusplus cpp
Last synced: over 1 year ago
JSON representation
A bunch of C++ code snippets for tackling LeetCode problems
- Host: GitHub
- URL: https://github.com/hesic73/snippets
- Owner: hesic73
- License: mit
- Created: 2023-12-26T23:01:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T01:00:30.000Z (over 1 year ago)
- Last Synced: 2025-03-17T20:44:44.030Z (over 1 year ago)
- Topics: c-plus-plus, cplusplus, cpp
- Language: C++
- Homepage: https://hesic73.github.io/snippets
- Size: 1.64 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# snippets


[](https://raw.githubusercontent.com/hesic73/snippets/master/LICENSE)
(hopefully) useful code snippets for LeetCode.
## Overview
| 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](https://leetcode.com/problems/minimum-index-of-a-valid-split/description/) |
| 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](https://leetcode.com/problems/the-skyline-problem/submissions/1172986139/). |
| disjoint_set.hpp | with the help of GPT-4 |
| big_integer.hpp | with the help of GPT-4 |
## Usage
To incorporate `snippets` into your C++ project, you can use CMake's `FetchContent` module as shown below:
```cmake
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:
```C++
#include
#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;
}
```
## Running Tests
The test appears in this manner:
```bash
mkdir -p build
cd build
cmake ..
cmake --build . --config Release
ctest -V -C Release
```