{"data":{"billing":{"currency":"USD","mode":"rules","parameters":[],"policy_version":2,"sale":{"addons":[],"base_price_micro_usd":"0","max_cost_micro_usd":"2000","quantities":[{"id":"upstream_credits","label":"Actual API.SH credits consumed","max_quantity":"1","measure":"value","pointer":"/credits_used","price_micro_usd":"2000","quantity_scale":0,"source":"response","unit":"credit","unit_quantity":"1"}],"rounding":"ceil","variants":[]}},"capabilityId":"6974cf48-404c-4787-a733-31c6ea41d7e0","catalogType":"api","categories":["developer","data"],"dataPlatform":"leetcode","dataPlatformLogoUrl":"https://api.sh/logos/leetcode.png","dataPlatformTranslations":{},"dataProduct":"coding-problems","description":"Get LeetCode Solution Post data via REST or OpenAny MCP—with pay-per-use pricing and no subscription. Powered by Apish, pass parameters such as id, output, raw, and retrieve structured data including post identifier, post title, published post content, author metadata, and associated problem reference to inspect selected explanations, and connect problem context.","descriptionTranslations":{"ar":"استرجع منشور شرح LeetCode عبر OpenAny REST لفحص التفسير ومصدره وسياق المسألة. أرسل المعرف أو الرابط لاستلام المحتوى والملخص والوسوم والتفاعلات والتعليقات والمراجع السابقة واللاحقة بصيغة JSON دون تنفيذ الحل أو التحقق من كوده.","ja":"OpenAny REST で LeetCode 解説投稿を取得し、説明と著者・問題の文脈を確認できます。投稿 ID または URL から本文、要約、タグ、反応、コメント情報、前後参照を JSON で取得し、コードの実行とは区別します。","zh":"通过 OpenAny REST 查询 LeetCode 题解帖子，阅读解释并保留作者和题目背景。传入帖子 ID 或链接，获取正文、摘要、标签、互动、评论信息和前后引用 JSON；不会执行或验证题解代码。"},"effectContentHtml":"","executionMode":"sync","id":"8335ae75-d1ac-4d70-bcc2-8743c6b54e59","includedContentHtml":"","inputs":[{"description":"Post id, or a leetcode.com/problems/\u003cslug\u003e/solutions/\u003cid\u003e/ link.","location":"query","name":"id","nullable":false,"required":true,"type":"string"},{"description":"0 leaves out the bulky `raw` source blocks (often 10-30x smaller).","enum_values":["0","1"],"location":"query","name":"raw","nullable":false,"required":false,"type":"string"},{"description":"Comma-separated fields to return, e.g. `posts.id,posts.title`. Call metadata is always included.","location":"query","name":"fields","nullable":false,"required":false,"type":"string"},{"description":"1 skips the 24-hour cache and fetches live.","enum_values":["1"],"location":"query","name":"fresh","nullable":false,"required":false,"type":"string"},{"description":"JSON only for this OpenAny product. Omit output or use json; CSV and NDJSON are not supported.","enum_values":["json"],"location":"query","name":"output","nullable":false,"required":false,"type":"string"},{"description":"With output=csv|ndjson: the top-level list to turn into rows (e.g. `reviews`), or `.` for the whole object as one row.","location":"query","name":"records","nullable":false,"required":false,"type":"string"}],"logoUrl":"https://api.sh/logos/leetcode.png","method":"GET","name":"LeetCode solution post API","nameTranslations":{},"overviewHtml":"\u003ch2\u003eLeetCode Solution Post API\u003c/h2\u003e\n\u003cp\u003eid identifies a solution post, not a problem. problem provides the associated problem context; official is a per-post source flag.\u003c/p\u003e\n\u003ch2\u003eQuick Facts\u003c/h2\u003e\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eFact\u003c/th\u003e\n\u003cth\u003eValue\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003eAccess\u003c/td\u003e\n\u003ctd\u003eOpenAny REST\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eAuthentication\u003c/td\u003e\n\u003ctd\u003eOpenAny API key in the Authorization header\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eCore inputs\u003c/td\u003e\n\u003ctd\u003eRequired inputs: id. JSON only; fresh=1 bypasses cache and raw=0 trims raw source blocks.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eSelected implementation\u003c/td\u003e\n\u003ctd\u003eapish · LeetCode solution post API\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eBilling\u003c/td\u003e\n\u003ctd\u003eSee the pricing area for the selected implementation and request options\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003ch2\u003eWhat You Can Build\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eInspect selected explanations\u003c/strong\u003e: Keep author and source URL with content.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eConnect problem context\u003c/strong\u003e: Retain problem separately from post identity.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2\u003eReturned Data\u003c/h2\u003e\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eField\u003c/th\u003e\n\u003cth\u003eMeaning\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003etopic_id\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003ePost identifier\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003etitle\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003ePost title\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003econtent\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003ePublished post content\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eauthor\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eAuthor metadata\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eproblem\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eAssociated problem reference\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eofficial\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eSource official-post flag\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003ecomments\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003ePublished comment metadata\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003ch2\u003eQuick Start\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003eSet OPENANY_API_KEY to your OpenAny API key.\u003c/li\u003e\n\u003cli\u003eReview the selected implementation and pricing, then adapt the request below to your target.\u003c/li\u003e\n\u003cli\u003eCheck the HTTP response and business result before reading optional fields.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cpre\u003e\u003ccode class=\"language-bash\"\u003ecurl --request GET --get \\\n  https://api.openany.si/v1/agent-apis/apish/leetcode/v1/discuss/post \\\n  -H \u0026#34;Authorization: Bearer ${OPENANY_API_KEY}\u0026#34; \\\n  --data-urlencode id=127810 \\\n  --data-urlencode output=json \\\n  --data-urlencode raw=0\n\u003c/code\u003e\u003c/pre\u003e\n\u003ch2\u003eRequest and Response Examples\u003c/h2\u003e\n\u003cp\u003eThe response example is a documentation reference and may be abbreviated. The documented request is a calling template; use the published contract and returned response for the selected implementation.\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://openany.si/api/v1/agent-apis/8335ae75-d1ac-4d70-bcc2-8743c6b54e59\"\u003ePublished LeetCode Solution Post API implementation contract\u003c/a\u003e.\u003c/p\u003e\n\u003ch2\u003ePricing and Billing\u003c/h2\u003e\n\u003cp\u003eThe pricing area reflects the selected API implementation. Review its billing unit and any request-dependent rules before calling; a source service\u0026#39;s public availability does not determine OpenAny billing.\u003c/p\u003e\n\u003ch2\u003eFrequently Asked Questions\u003c/h2\u003e\n\u003ch3\u003eDo I supply a problem ID?\u003c/h3\u003e\n\u003cp\u003eNo. Use a solution post ID or supported solution URL.\u003c/p\u003e\n\u003ch3\u003eWhere can I find post IDs?\u003c/h3\u003e\n\u003cp\u003eUse topic_id from Solution Search results.\u003c/p\u003e\n\u003ch3\u003eDoes this execute the included code?\u003c/h3\u003e\n\u003cp\u003eNo. It reads published content.\u003c/p\u003e\n\u003ch3\u003eAre previous and next pagination tokens?\u003c/h3\u003e\n\u003cp\u003eThey are returned post references; this request exposes only id.\u003c/p\u003e\n\u003ch3\u003eIs every post an official solution?\u003c/h3\u003e\n\u003cp\u003eNo. Read official for the returned post.\u003c/p\u003e\n\u003ch3\u003eCan I request CSV or NDJSON?\u003c/h3\u003e\n\u003cp\u003eThis OpenAny implementation serves JSON only. Omit output or use output=json.\u003c/p\u003e\n\u003ch2\u003eRelated APIs\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://openany.si/market/apis/leetcode/leetcode-contest-api\"\u003eLeetCode contest API\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://openany.si/market/apis/leetcode/leetcode-contest-ranking-api\"\u003eLeetCode contest ranking API\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://openany.si/market/apis/leetcode/leetcode-contests-api\"\u003eLeetCode contests API\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n","pagePath":"/markets/apis/leetcode/leetcode-solution-post-api?offering=8335ae75-d1ac-4d70-bcc2-8743c6b54e59","providerId":"apish","publicPath":"/v1/agent-apis/apish/leetcode/v1/discuss/post","requestContentType":"none","revision":3,"samples":[{"http_status":200,"name":"Official example · Live API.SH response · Minimal request","request":{"body":null,"headers":{},"path":{},"query":{"id":"127810","output":"json","raw":"0"}},"response_body":{"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\u003clcvideo\u003e\n    \u003cdiv class=\"video-container\"\u003e\n        \u003ciframe src=\"https://player.vimeo.com/video/567281997\" width=\"640\" height=\"360\" frameborder=\"0\" allow=\"autoplay; fullscreen\" allowfullscreen\u003e\u003c/iframe\u003e\n    \u003c/div\u003e\n\u003c/lcvideo\u003e\n\n\u003cdiv\u003e\u0026nbsp;\n\u003c/div\u003e\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\u003ciframe src=\"https://leetcode.com/playground/WTVGRyeD/shared\" frameBorder=\"0\" width=\"100%\" height=\"327\" name=\"WTVGRyeD\"\u003e\u003c/iframe\u003e\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\u003ciframe src=\"https://leetcode.com/playground/bbEpXJcf/shared\" frameBorder=\"0\" width=\"100%\" height=\"500\" name=\"bbEpXJcf\"\u003e\u003c/iframe\u003e  \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\u003ciframe src=\"https://leetcode.com/playground/4KK3DMtw/shared\" frameBorder=\"0\" width=\"100%\" height=\"500\" name=\"4KK3DMtw\"\u003e\u003c/iframe\u003e\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}}],"seoDescription":"Get LeetCode Solution Post data via REST or MCP powered by Apish. Pay per call, no subscription. Get post identifier and post title in JSON.","updatedAt":"2026-12-03T02:44:06.541Z","usageInstructionsHtml":""}}