1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/originData/print-in-order.json

94 lines
13 KiB
JSON
Raw Normal View History

2022-03-27 18:35:17 +08:00
{
"data": {
"question": {
"questionId": "1203",
"questionFrontendId": "1114",
"boundTopicId": null,
"title": "Print in Order",
"titleSlug": "print-in-order",
2023-12-09 18:42:21 +08:00
"content": "<p>Suppose we have a class:</p>\n\n<pre>\npublic class Foo {\n public void first() { print(&quot;first&quot;); }\n public void second() { print(&quot;second&quot;); }\n public void third() { print(&quot;third&quot;); }\n}\n</pre>\n\n<p>The same instance of <code>Foo</code> will be passed to three different threads. Thread A will call <code>first()</code>, thread B will call <code>second()</code>, and thread C will call <code>third()</code>. Design a mechanism and modify the program to ensure that <code>second()</code> is executed after <code>first()</code>, and <code>third()</code> is executed after <code>second()</code>.</p>\n\n<p><strong>Note:</strong></p>\n\n<p>We do not know how the threads will be scheduled in the operating system, even though the numbers in the input seem to imply the ordering. The input format you see is mainly to ensure our tests&#39; comprehensiveness.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3]\n<strong>Output:</strong> &quot;firstsecondthird&quot;\n<strong>Explanation:</strong> There are three threads being fired asynchronously. The input [1,2,3] means thread A calls first(), thread B calls second(), and thread C calls third(). &quot;firstsecondthird&quot; is the correct output.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,2]\n<strong>Output:</strong> &quot;firstsecondthird&quot;\n<strong>Explanation:</strong> The input [1,3,2] means thread A calls first(), thread B calls third(), and thread C calls second(). &quot;firstsecondthird&quot; is the correct output.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>nums</code> is a permutation of <code>[1, 2, 3]</code>.</li>\n</ul>\n",
2022-03-27 18:35:17 +08:00
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
2023-12-09 18:42:21 +08:00
"likes": 1404,
"dislikes": 196,
2022-03-27 18:35:17 +08:00
"isLiked": null,
"similarQuestions": "[{\"title\": \"Print FooBar Alternately\", \"titleSlug\": \"print-foobar-alternately\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "[1,2,3]\n[1,3,2]",
"categoryTitle": "Concurrency",
"contributors": [],
"topicTags": [
{
"name": "Concurrency",
"slug": "concurrency",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Foo {\npublic:\n Foo() {\n \n }\n\n void first(function<void()> printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n void second(function<void()> printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n void third(function<void()> printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Foo {\n\n public Foo() {\n \n }\n\n public void first(Runnable printFirst) throws InterruptedException {\n \n // printFirst.run() outputs \"first\". Do not change or remove this line.\n printFirst.run();\n }\n\n public void second(Runnable printSecond) throws InterruptedException {\n \n // printSecond.run() outputs \"second\". Do not change or remove this line.\n printSecond.run();\n }\n\n public void third(Runnable printThird) throws InterruptedException {\n \n // printThird.run() outputs \"third\". Do not change or remove this line.\n printThird.run();\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Foo(object):\n def __init__(self):\n pass\n\n\n def first(self, printFirst):\n \"\"\"\n :type printFirst: method\n :rtype: void\n \"\"\"\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond):\n \"\"\"\n :type printSecond: method\n :rtype: void\n \"\"\"\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n \n \n def third(self, printThird):\n \"\"\"\n :type printThird: method\n :rtype: void\n \"\"\"\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Foo:\n def __init__(self):\n pass\n\n\n def first(self, printFirst: 'Callable[[], None]') -> None:\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond: 'Callable[[], None]') -> None:\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n\n\n def third(self, printThird: 'Callable[[], None]') -> None:\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "typedef struct {\n // User defined data may be declared here.\n \n} Foo;\n\nFoo* fooCreate() {\n Foo* obj = (Foo*) malloc(sizeof(Foo));\n \n // Initialize user defined data here.\n \n return obj;\n}\n\nvoid first(Foo* obj) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n}\n\nvoid second(Foo* obj) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n}\n\nvoid third(Foo* obj) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n}\n\nvoid fooFree(Foo* obj) {\n // User defined data may be cleaned up here.\n \n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Foo {\n\n public Foo() {\n \n }\n\n public void First(Action printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n public void Second(Action printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n public void Third(Action printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n}",
"__typename": "CodeSnippetNode"
}
],
2023-12-09 18:42:21 +08:00
"stats": "{\"totalAccepted\": \"144.9K\", \"totalSubmission\": \"209.7K\", \"totalAcceptedRaw\": 144879, \"totalSubmissionRaw\": 209684, \"acRate\": \"69.1%\"}",
2022-03-27 18:35:17 +08:00
"hints": [],
"solution": {
"id": "775",
"canSeeDetail": false,
"paidOnly": true,
"hasVideoSolution": false,
"paidOnlyVideo": true,
"__typename": "ArticleNode"
},
"status": null,
"sampleTestCase": "[1,2,3]",
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"name\": \"nums\",\n \"type\": \"integer[]\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"java\",\n \"cpp\",\n \"python\",\n \"python3\",\n \"c\",\n \"csharp\"\n ],\n \"manual\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": false,
2023-12-09 18:42:21 +08:00
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 20 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code>OpenJDK 17</code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu11 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\"], \"python3\": [\"Python3\", \"<p><code>Python 3.10</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/3/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/3/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/3/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\"
2022-03-27 18:35:17 +08:00
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}