1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-21 13:06:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-09-29 14:43:44 +08:00
parent 2862a227c4
commit 13f2098086
4409 changed files with 168933 additions and 166256 deletions

View File

@@ -12,12 +12,12 @@
"translatedContent": "<p>给你一个类:</p>\n\n<pre>\nclass FooBar {\n public void foo() {\n&nbsp; &nbsp; for (int i = 0; i &lt; n; i++) {\n&nbsp; &nbsp; &nbsp; print(\"foo\");\n&nbsp; }\n }\n\n public void bar() {\n&nbsp; &nbsp; for (int i = 0; i &lt; n; i++) {\n&nbsp; &nbsp; &nbsp; print(\"bar\");\n&nbsp; &nbsp; }\n }\n}\n</pre>\n\n<p>两个不同的线程将会共用一个 <code>FooBar</code>&nbsp;实例:</p>\n\n<ul>\n\t<li>线程 A 将会调用&nbsp;<code>foo()</code>&nbsp;方法,而</li>\n\t<li>线程 B 将会调用&nbsp;<code>bar()</code>&nbsp;方法</li>\n</ul>\n\n<p>请设计修改程序,以确保 <code>\"foobar\"</code> 被输出 <code>n</code> 次。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 1\n<strong>输出:</strong>\"foobar\"\n<strong>解释:</strong>这里有两个线程被异步启动。其中一个调用 foo() 方法, 另一个调用 bar() 方法,\"foobar\" 将被输出一次。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 2\n<strong>输出:</strong>\"foobarfoobar\"\n<strong>解释:</strong>\"foobar\" 将被输出两次。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n &lt;= 1000</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 208,
"likes": 214,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Print in Order\", \"titleSlug\": \"print-in-order\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u6309\\u5e8f\\u6253\\u5370\", \"isPaidOnly\": false}, {\"title\": \"Print Zero Even Odd\", \"titleSlug\": \"print-zero-even-odd\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u6253\\u5370\\u96f6\\u4e0e\\u5947\\u5076\\u6570\", \"isPaidOnly\": false}]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false, \"cangjie\": false}",
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python3\": true, \"python\": true, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": false}",
"topicTags": [
{
"name": "Concurrency",
@@ -40,12 +40,6 @@
"code": "class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo.run() outputs \"foo\". Do not change or remove this line.\n \tprintFoo.run();\n }\n }\n\n public void bar(Runnable printBar) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n // printBar.run() outputs \"bar\". Do not change or remove this line.\n \tprintBar.run();\n }\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class FooBar(object):\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo):\n \"\"\"\n :type printFoo: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar):\n \"\"\"\n :type printBar: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
@@ -53,9 +47,9 @@
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "typedef struct {\n int n;\n} FooBar;\n\n// Function declarations. Do not change or remove this line\nvoid printFoo();\nvoid printBar();\n\nFooBar* fooBarCreate(int n) {\n FooBar* obj = (FooBar*) malloc(sizeof(FooBar));\n obj->n = n;\n return obj;\n}\n\nvoid foo(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printFoo() outputs \"foo\". Do not change or remove this line.\n printFoo();\n }\n}\n\nvoid bar(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n printBar();\n }\n}\n\nvoid fooBarFree(FooBar* obj) {\n \n}",
"lang": "Python",
"langSlug": "python",
"code": "class FooBar(object):\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo):\n \"\"\"\n :type printFoo: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar):\n \"\"\"\n :type printBar: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()",
"__typename": "CodeSnippetNode"
},
{
@@ -64,6 +58,12 @@
"code": "public class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void Foo(Action printFoo) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo();\n }\n }\n\n public void Bar(Action printBar) {\n \n for (int i = 0; i < n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar();\n }\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "typedef struct {\n int n;\n} FooBar;\n\n// Function declarations. Do not change or remove this line\nvoid printFoo();\nvoid printBar();\n\nFooBar* fooBarCreate(int n) {\n FooBar* obj = (FooBar*) malloc(sizeof(FooBar));\n obj->n = n;\n return obj;\n}\n\nvoid foo(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printFoo() outputs \"foo\". Do not change or remove this line.\n printFoo();\n }\n}\n\nvoid bar(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n printBar();\n }\n}\n\nvoid fooBarFree(FooBar* obj) {\n \n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Go",
"langSlug": "golang",
@@ -71,7 +71,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"78.3K\", \"totalSubmission\": \"133.4K\", \"totalAcceptedRaw\": 78266, \"totalSubmissionRaw\": 133413, \"acRate\": \"58.7%\"}",
"stats": "{\"totalAccepted\": \"84.6K\", \"totalSubmission\": \"142.4K\", \"totalAcceptedRaw\": 84587, \"totalSubmissionRaw\": 142404, \"acRate\": \"59.4%\"}",
"hints": [],
"solution": null,
"status": null,