LeetCode solution post API

Use the LeetCode solution post API to retrieve problem metadata, published summaries, author information, comment counts, topic tags and record identities and titles as structured JSON from LeetCode. Supply record identifier in the query. Use these results to find community explanations and connect problem references with relevant solution discussions. The documented source-page link form identifies the requested entry directly and lets you reuse an existing source-page reference. The detail page includes parameter definitions, paired request and response examples, and usage pricing for this operation.

Selected price
$0.002 / billing creditPublished pricing
Sellers / implementations
1 / 1
Requests · 30d
—Loading...
Success rate · 30d
—Loading...

Run sends a real API request. Charges follow the published API contract.

Request parameters
Post id, or a leetcode.com/problems/<slug>/solutions/<id>/ link.
Optional parameters (5)
0 leaves out the bulky `raw` source blocks (often 10-30x smaller).
Comma-separated fields to return, e.g. `posts.id,posts.title`. Call metadata is always included.
1 skips the 24-hour cache and fetches live.
JSON only for this OpenAny product. Omit output or use json; CSV and NDJSON are not supported.
With output=csv|ndjson: the top-level list to turn into rows (e.g. `reviews`), or `.` for the whole object as one row.

Sample response

{
  "author": {
    "avatar": "https://assets.leetcode.com/users/leetcode/avatar_1568224780.png",
    "name": "LeetCode",
    "username": "leetcode"
  },
  "cached": false,
  "comments": 3973,
  "content": "[TOC]\n\n## Video Solution\n\n---\n\n<lcvideo>\n    <div class=\"video-container\">\n        <iframe src=\"https://player.vimeo.com/video/567281997\" width=\"640\" height=\"360\" frameborder=\"0\" allow=\"autoplay; fullscreen\" allowfullscreen></iframe>\n    </div>\n</lcvideo>\n\n<div>&nbsp;\n</div>\n\n## Solution Article\n\n---\n\n### Approach 1: Brute Force\n\n**Algorithm**\n\nThe brute force approach is simple. Loop through each element $$x$$ and find if there is another value that equals to $$target - x$$.\n\n**Implementation**\n\n<iframe src=\"https://leetcode.com/playground/WTVGRyeD/shared\" frameBorder=\"0\" width=\"100%\" height=\"327\" name=\"WTVGRyeD\"></iframe>\n\n**Complexity Analysis**\n\n* Time complexity: $$O(n^2)$$.\nFor each element, we try to find its complement by looping through the rest of the array which takes $$O(n)$$ time. Therefore, the time complexity is $$O(n^2)$$.\n\n* Space complexity: $$O(1)$$.\nThe space required does not depend on the size of the input array, so only constant space is used.\n\n---\n### Approach 2: Two-pass Hash Table\n\n**Intuition**\n\nTo improve our runtime complexity, we need a more efficient way to check if the complement exists in the array. If the complement exists, we need to get its index. What is the best way to maintain a mapping of each element in the array to its index? A hash table.\n\nWe can reduce the lookup time from $$O(n)$$ to $$O(1)$$ by trading space for speed. A hash table is well suited for this purpose because it supports fast lookup in *near* constant time. I say \"near\" because if a collision occurred, a lookup could degenerate to $$O(n)$$ time. However, lookup in a hash table should be amortized $$O(1)$$ time as long as the hash function was chosen carefully.\n\n**Algorithm**\n\nA simple implementation uses two iterations. In the first iteration, we add each element's value as a key and its index as a value to the hash table. Then, in the second iteration, we check if each element's complement ($$target - nums[i]$$) exists in the hash table. If it does exist, we return current element's index and its complement's index. Beware that the complement must not be $$nums[i]$$ itself!\n\n**Implementation**\n\n<iframe src=\"https://leetcode.com/playground/bbEpXJcf/shared\" frameBorder=\"0\" width=\"100%\" height=\"500\" name=\"bbEpXJcf\"></iframe>  \n\n**Complexity Analysis**\n\n* Time complexity: $$O(n)$$.\nWe traverse the list containing $$n$$ elements exactly twice. Since the hash table reduces the lookup time to $$O(1)$$, the overall time complexity is $$O(n)$$.\n\n* Space complexity: $$O(n)$$.\nThe extra space required depends on the number of items stored in the hash table, which stores exactly $$n$$ elements.\n\n---\n### Approach 3: One-pass Hash Table\n\n**Algorithm**\n    \nIt turns out we can do it in one-pass. While we are iterating and inserting elements into the hash table, we also look back to check if current element's complement already exists in the hash table. If it exists, we have found a solution and return the indices immediately.\n\n**Implementation**    \n    \n<iframe src=\"https://leetcode.com/playground/4KK3DMtw/shared\" frameBorder=\"0\" width=\"100%\" height=\"500\" name=\"4KK3DMtw\"></iframe>\n\n**Complexity Analysis**\n\n* Time complexity: $$O(n)$$.\nWe traverse the list containing $$n$$ elements only once. Each lookup in the table costs only $$O(1)$$ time.\n\n* Space complexity: $$O(n)$$.\nThe extra space required depends on the number of items stored in the hash table, which stores at most $$n$$ elements.",
  "created_at": "2021-06-25T02:47:00+00:00",
  "credits_used": 1,
  "downvotes": 361,
  "fetched_at": "2026-11-19T12:29:39.866Z",
  "has_video": true,
  "next": {
    "slug": "video-step-by-step-easy-solution-by-niit-ydj9",
    "title": "【Video】Step by Step Easy Solution",
    "topic_id": 8586852
  },
  "official": true,
  "previous": null,
  "problem": {
    "slug": "two-sum",
    "title": "Two Sum",
    "url": "https://leetcode.com/problems/two-sum/"
  },
  "reactions": {
    "thumbs_down": 361,
    "upvote": 5141
  },
  "slug": "two-sum-by-leetcode-kwuq",
  "summary": "Video Solution   Solution Article Approach 1: Brute Force Algorithm The brute force approach is simple. Loop through each element x and find if there is another",
  "tags": [],
  "title": "Two Sum",
  "top_level_comments": 2831,
  "topic_id": 127810,
  "updated_at": "2021-06-25T02:47:00+00:00",
  "upvotes": 5141,
  "url": "https://leetcode.com/problems/two-sum/solutions/127810/two-sum-by-leetcode-kwuq",
  "views": 14531684
}

Response result

Response structure

Inferred from examples
  • authorobject
    • avatarstring
    • namestring
    • usernamestring
  • cachedboolean
  • commentsinteger
  • contentstring
  • created_atstring
  • credits_usedinteger
  • downvotesinteger
  • fetched_atstring
  • has_videoboolean
  • nextobject
    • slugstring
    • titlestring
    • topic_idinteger
  • officialboolean
  • previousnull
  • problemobject
    • slugstring
    • titlestring
    • urlstring
  • reactionsobject
    • thumbs_downinteger
    • upvoteinteger
  • slugstring
  • summarystring
  • tagsunknown[]
  • titlestring
  • top_level_commentsinteger
  • topic_idinteger
  • updated_atstring
  • upvotesinteger
  • urlstring
  • viewsinteger

Common questions

Do I need a separate key for every provider?

Use your OpenAny API key for standard API access. Read it from OPENANY_API_KEY in your environment and keep it out of prompts, source code and logs.

Are these providers interchangeable?

No. Each offering has its own inputs, pricing and response contract. Selecting a catalog offering does not establish automatic routing or fallback. Confirm the service contract before calling.

How is this API billed?

API-key calls use your shared balance at the selected implementation's published rate. Check the billing unit and request-specific pricing rules before making a paid call. Recorded usage determines the final charge under that contract.

Where do the price and contract come from?

The selected implementation publishes its provider, request contract, revision and billing rules through OpenAny's public API catalog. A revision number identifies a contract version, not a price update date. A price update timestamp is not supplied; do not treat a page date as one.

How do OpenAny Balance and x402 differ?

OpenAny Balance uses an API key and one shared balance. Card, USDC and x402 top-ups, card auto top-up and USDC subscriptions fund that balance; available routes appear on the Credits page. Direct x402 is a separate pay-per-request flow, available only on listings that show it and requiring an authorized payment client.

Does Playground send a paid request?

Yes. After you sign in, Run sends a real API request using an active OpenAny API key. Charges follow the published API contract and use your shared balance. Selecting an implementation, editing inputs and viewing sample responses do not send requests.

Use LeetCode solution post API with your agent

Inspect endpoint contracts and confirm availability and pricing before a paid call.