qianbinbin / leetcode

LeetCode Solutions in C, C++, Java and Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LeetCode Solutions in C, C++, Java and Python

C/C++

CLion is recommended.

NOTE: always reload CMake after adding new unit tests.

Requirements

  • A compiler with C99 and C++11 support.

Manually

CMake is required.

Generate a buildsystem:

$ cd /path/to/leetcode/c/  # /path/to/leetcode/cpp/
$ mkdir build
$ cd build
$ cmake ..
$ cd ..

CMake will automatically generate buildsystem files and download googletest.

NOTE: always reload CMake after adding new unit tests.

To build, specify unit test with --target:

$ cmake --build build --target two_sum_test -- -j4
[  2%] Built target gtest
[ 97%] Built target lc
[ 97%] Built target gtest_main
Scanning dependencies of target two_sum_test
[100%] Building CXX object tests/CMakeFiles/two_sum_test.dir/two_sum_test.cpp.o
[100%] Linking CXX executable two_sum_test
[100%] Built target two_sum_test

Run the test:

$ ./build/tests/two_sum_test
Running main() from /path/to/leetcode/c/build/googletest-src/googletest/src/gtest_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from two_sum_test
[ RUN      ] two_sum_test.twoSum_1_1
[       OK ] two_sum_test.twoSum_1_1 (0 ms)
[----------] 1 test from two_sum_test (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test

Java

IntelliJ IDEA is recommended.

Requirements

  • JDK 8 or newer.

Python

PyCharm is recommended.

Requirements

  • Python3.

Manually

Run a specific unit test:

$ cd /path/to/leetcode/python/
$ python3 -m unittest tests/test_two_sum.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

About

LeetCode Solutions in C, C++, Java and Python

License:MIT License


Languages

Language:Java 35.3%Language:C++ 28.2%Language:C 18.4%Language:Python 17.3%Language:Shell 0.5%Language:CMake 0.3%