alfonsogonzalez / algos

Leetcode Algorithms with C++ and Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

algos - Leetcode Algorithms with Python and C++

Dependencies

  • (C++) C++ Compiler ( g++ or clang++ )
  • (C++) cmake (optional but recommended)
  • (Python) Python 3.0+
  • (Python) pytest

Installing Python dependencies

Python packages can be easily and conveniently installed using pip via the command line like so:

$ python3 -m pip install {package_name}

In the case of algos, all Python dependencies can be installed in one command using the requirements.txt file as so:

$ python3 -m pip install -r requirements.txt

C++ Compiling

This repository can be built as a cmake project or can be used with the standalone C++ scripts.

cmake

The following are the steps to compile the C++ portion of this repostiory with cmake (starting from the base of the repository):

$ mkdir build
$ cd build
$ cmake ../src/
$ make

The last 2 commands can be optionally run with the -j flag for multithreading. For example:

$ make -j4

Standalone

If you are unfamiliar with / don't want to use cmake, there are standalone C++ scripts that can be quickly compiled and run with a simple call to g++ or clang++. These scripts can be found at: src/cpp/standalone.

Each standalone script is accompanied by a bash script that:

  1. Calls g++ to compile standalone and implementation scripts
  2. Calls executable
  3. Deletes executable

One can replace "g++" with "clang++" in the bash scripts if desired.

These bash scripts use an environment variable ALGOS that points to the src directory of this repository. This variable can be easily set with the export command. For example:

$ export ALGOS=/home/alfonso/pub/algos/src

Once the ALGOS environment variable is set, one can run the bash scripts from any directory. For example, from the base of this repository:

$ ./src/cpp/standalone/reverse_string_run.sh
13
astrodynamics
scimanydortsa

Unit Tests

Both the C++ and Python portions of this repository have unit tests implemented. The C++ portion uses GoogleTest and the Python portion uses pytest.

C++

After compiling, one can simply run the unit tests with the ctest command (with optional flags)

$ ctest -j4 -V # V for verbose output, if desired

Python

The Python unit tests in this repository can be run exactly the same as in the Astrodynamics with Python repository:

$ python3 -m pytest src/py/ -vv
$ pytest src/py/ -vv

About

Leetcode Algorithms with C++ and Python


Languages

Language:C++ 66.6%Language:Python 23.3%Language:CMake 6.9%Language:Shell 3.2%