This was created for ease of solving LeetCode problems locally. The template is able to parse LeetCode inputs and constructs the appropriate data to pass into the solution. Integration with editors requires minimal work since this template was designed to be minimal.
- Parses LeetCode inputs from stdin and outputs to stdout
- Requires C++ macro
LC_LOCAL
to be defined! Do it within your compile command by passing-DLC_LOCAL
as an argument like:g++ {current_file} -DLC_LOCAL
. The run scripts does this for you already. - Each line of the testcase should end with a newline (enter key)
- To signal that you're done with the testcase, simply pretty enter without entering anything
- If the input is ill-formed or does not match the parameter types, the behavior is undefined!
- Requires C++ macro
- Comes with templates for various data structures and algorithms
- A debug macro
dbg
to pretty-print multiple variables at once to stderr (up to 10 perdbg
call) - Copy the entire file for submission
- To set up for a LeetCode problem, copy
template.cpp
to another file (commonlymain.cpp
) and change the following parts:
-
// ----- CHANGE FOR PROBLEM ----- class Solution { public: void test() {} }; // ----- CHANGE FOR PROBLEM -----
-
exec(&Solution::test); // CHANGE FOR PROBLEM
- Run
run.sh _your_solution_filename_
(orrun.bat
, and make sureg++
is inPATH
)
- If you want to use a file as input, run
run.sh _your_solution_filename_ < _your_input_filename_
- Similarly, if you want to output to a file, run
run.sh _your_solution_filename_ > _your_output_filename_
map<int, vector<pair<int, int>>> a{{3, {{4, 5}, {6, 7}}}};
int b = 1e9;
dbg(a, b);
// [a = [{3,[{4,5},{6,7}]}]] [b = 1000000000]