LeetCode-OpenSource / vscode-leetcode

Solve LeetCode problems in VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-leetcode
MIT License
8.22k stars 650 forks source link

How can i debug my code #244

Closed loisjee closed 5 years ago

loisjee commented 5 years ago

Hello! I want to know how can i debug my code after i finish my solution in vscode. can anybody help me

jdneo commented 5 years ago

Hi @SongJee,

Debug is not supported yet. If you want to debug your solution, you need to install related language extensions and write some code to wrap your solution.

littlebeandog commented 5 years ago

I dont think this is a concern of this extension though.....

Vigilans commented 5 years ago

If you write your solution in cpp, you could take a look at the discussion in #241.

This feature is currently under early discussion, and is a concern of mine.

Luanf commented 5 years ago

Just wanted to add that my approach has been using the CodeRunner extension: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

I then add a call to the solution function, like so:

// Pre generated template
solution(...) {
    ...
}
// I add this line so running CodeRunner executes the function
solution()

Of course you can then add inputs to it:

a = 'foo'
b = 'bar'
solution(a, b)

Depending on the problem.

BrambleXu commented 5 years ago

You can write test cases by yourself. Here is mine.

if __name__ == "__main__":
    s = Solution()
    testcases = [
                 ("USA", True), 
                 ("leetcode", True),
                 ("Facebook", True),
                 ("HaWa", False),
                 ]
    for i, (inp, ans) in enumerate(testcases):
        print("Test case: ", i)
        print("answer:   ", s.detectCapitalUse(inp))
        print("expected: ", ans)
        print()

As @littlebeandog said, the test is not a concern for this extension. This should be closed.

jdneo commented 5 years ago

Thank you @All for providing the solutions.

I'm closing the issue for now, but the discussion is still open!

For anyone who has his own solution about debugging the code, please feel free to comment.

You can also add 👍 for your favorite solution, which could be a guide for those who need help.