- English Document | 中文文档
Attention: Before start debugging, you must to check availability of your C++ debugger tools. Get more information from VSCode documents.
-
Generate debugging codes and start a debug session for your solution.
-
You can run the
LeetCode Debugger: Start Debuggingcommand from the command palette (Ctrl/Cmd + Shift + P).
-
Code template is used to generate the debugging code.
-
Online: Fetching problem from
LeetCode. Requires your solution file to start with problem ID, for example,1.two-sum.cpp(Or you can modify the regular expression for capturing problem ID in extension settings). -
Offline: Using your solution code as code template.
-
You could use the code below to change the input/output:
#define INPUT "test_case.txt" // single-input #define OUTPUT cout, "output.txt" // multi-output
-
For
INPUT, bothstd::istreamandstd::string(input from file) are acceptable, but you can only have ONE input. -
For
OUTPUT, bothstd::ostreamandstd::string(output to file) are acceptable, you can have multiple outputs.
-
Interactive problem is NOT supported yet.
-
But you can realize the interactive function by yourself! Know more from API and examples. Here is an example for problem 278.
#ifdef LEETCODE_DEFINITION // protection int firstVersion; // the first bad version bool isBadVersion(int version) { // realization return version >= firstVersion; } #define LAZY_INTERACTION firstVersion // input firstVersion #endif
-
LAZY_INTERACTIONmeans interactive inputs after function's arguments,INTERACTIONmeans interactive inputs before function's arguments, in addition, function with typevoid ()is also acceptable. The example below will help you to understand these stuff.#ifdef LEETCODE_DEFINITION // protection int value1, value2; // interactive values void before() { value1 *= 2; } void after() { value2 *= value1; } #define INTERACTION value1, before // input value1, then call the function 'before()' #define LAZY_INTERACTION value2, after // input value2, then call the function 'after()' #endif class Solution { public: int exampleFunction(int v) { return v * value1 * value2; } }; /* * input: * 1 // -> value1 -> value1*=2 -> 2 * 2 // -> v * 3 // -> value2 -> value2*=value1 -> 6 * output: * 24 // -> v*value1*value2 -> 2*2*6=24 * /
| Setting Name | Description | Default Value |
|---|---|---|
Source |
Source of code template for generating debugging code. | "[online]leetcode.com" |
Delete Temporary Contents |
Delete temporary codes and files after debugging. | true |
Id Match Pattern |
Regular expression for capturing problem ID when fetching problem online. | "(\\d+).*" |
Output File Encoding |
Encoding of temporary code files | "utf8" |
- The default value of
Id Match Patterncan match any file name begin with a number.
Refer to CHANGELOG.
You can solve LeetCode problems in VSCode with another amazing extension LeetCode.
