Using LeetCode Run Code for Faster Debugging
Learn how LeetCode’s Run Code button gives instant feedback, letting you test custom inputs, spot bugs early, and reduce failed submissions before you hit Submit.
04 Feb 2026, 03:44 UTC

Why debugging on LeetCode can feel slow
\nWhen you submit a solution and see a red cross, you only know that something failed, but you don’t see why. Without immediate feedback you may guess at the problem, resubmit, and waste cycles.
\n\nThesis: Run Code gives you a fast feedback loop
\nThe Run Code button lets you execute your code against a custom test case instantly, showing output, runtime and memory usage. This mirrors the judge’s limits while letting you verify logic before you commit a submission.
\n\nHow Run Code works under the hood
\n- \n
- You write or paste your solution in the editor. \n
- Choose a language (Python 3, Java 8, C++17, etc.). \n
- Press the Run Code button. \n
- LeetCode compiles the code on its sandbox servers, runs it with the supplied input, and enforces the same time (typically 2 s) and memory limits as the real judge. \n
- The result pane prints the program’s stdout, any runtime error, and the measured runtime/memory. \n
Worked example: Two Sum
\n- \n
- Open the
Two Sumproblem. \n - Select Python 3 and paste a simple solution: \n
class Solution:\n def twoSum(self, nums, target):\n seen = {}\n for i, n in enumerate(nums):\n complement = target - n\n if complement in seen:\n return [seen[complement], i]\n seen[n] = i\n return []\n\n- \n
- In the “Custom Test Case” area, type the JSON‑style input LeetCode expects for this problem:
[2,7,11,15]on the first line and9on the second line (or the combined formatnums = [2,7,11,15], target = 9depending on the UI). \n - Click Run Code. \n
- The output pane shows
[0,1], runtime ~1 ms, memory ~10 MB. \n - Now change the input to an edge case, e.g., an empty array:
[]and0. Run again; you see an empty list[]with no error, confirming the code handles the case. \n - If you deliberately introduce a bug—forgetting to return a value—you will get a runtime error or wrong output, letting you fix it before submitting. \n
Trade‑offs and limitations
\n- \n
- Passing a custom test case does **not** guarantee acceptance; hidden test cases may still fail. \n
- The sandbox enforces a timeout (≈2 s) and memory limit; a solution that works locally with larger limits may appear correct in Run Code but hit a limit on the real judge. \n
- Run Code does not show the detailed test‑case breakdown that the Submit button provides after acceptance. \n
Actionable closing
\nMake Run Code your first step after writing a solution: verify syntax, basic logic, and edge cases with a few hand‑crafted inputs. Once you are confident, use Submit to run the full suite. This habit reduces failed submissions and tightens your feedback loop without leaving the LeetCode interface.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.