mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-25 14:58:56 +08:00
update
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
"translatedContent": "<p>现有函数 <code>printNumber</code> 可以用一个整数参数调用,并输出该整数到控制台。</p>\n\n<ul>\n\t<li>例如,调用 <code>printNumber(7)</code> 将会输出 <code>7</code> 到控制台。</li>\n</ul>\n\n<p>给你类 <code>ZeroEvenOdd</code> 的一个实例,该类中有三个函数:<code>zero</code>、<code>even</code> 和 <code>odd</code> 。<code>ZeroEvenOdd</code> 的相同实例将会传递给三个不同线程:</p>\n\n<ul>\n\t<li><strong>线程 A:</strong>调用 <code>zero()</code> ,只输出 <code>0</code></li>\n\t<li><strong>线程 B:</strong>调用 <code>even()</code> ,只输出偶数</li>\n\t<li><strong>线程 C:</strong>调用 <code>odd()</code> ,只输出奇数</li>\n</ul>\n\n<p>修改给出的类,以输出序列 <code>\"010203040506...\"</code> ,其中序列的长度必须为 <code>2n</code> 。</p>\n\n<p>实现 <code>ZeroEvenOdd</code> 类:</p>\n\n<ul>\n\t<li><code>ZeroEvenOdd(int n)</code> 用数字 <code>n</code> 初始化对象,表示需要输出的数。</li>\n\t<li><code>void zero(printNumber)</code> 调用 <code>printNumber</code> 以输出一个 0 。</li>\n\t<li><code>void even(printNumber)</code> 调用<code>printNumber</code> 以输出偶数。</li>\n\t<li><code>void odd(printNumber)</code> 调用 <code>printNumber</code> 以输出奇数。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 2\n<strong>输出:</strong>\"0102\"\n<strong>解释:</strong>三条线程异步执行,其中一个调用 zero(),另一个线程调用 even(),最后一个线程调用odd()。正确的输出为 \"0102\"。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 5\n<strong>输出:</strong>\"0102030405\"\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 1000</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 161,
|
||||
"likes": 167,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Print FooBar Alternately\", \"titleSlug\": \"print-foobar-alternately\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4ea4\\u66ff\\u6253\\u5370 FooBar\", \"isPaidOnly\": false}, {\"title\": \"Fizz Buzz Multithreaded\", \"titleSlug\": \"fizz-buzz-multithreaded\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4ea4\\u66ff\\u6253\\u5370\\u5b57\\u7b26\\u4e32\", \"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 ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber.accept(x) outputs \"x\", where x is an integer.\n public void zero(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void even(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void odd(IntConsumer printNumber) throws InterruptedException {\n \n }\n}",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "Python",
|
||||
"langSlug": "python",
|
||||
"code": "class ZeroEvenOdd(object):\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def even(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def odd(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n ",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "Python3",
|
||||
"langSlug": "python3",
|
||||
@@ -53,9 +47,9 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "C",
|
||||
"langSlug": "c",
|
||||
"code": "typedef struct {\n int n;\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) {\n ZeroEvenOdd* obj = (ZeroEvenOdd*) malloc(sizeof(ZeroEvenOdd));\n obj->n = n;\n return obj;\n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\n\nvoid zero(ZeroEvenOdd* obj) {\n \n}\n\nvoid even(ZeroEvenOdd* obj) {\n \n}\n\nvoid odd(ZeroEvenOdd* obj) {\n \n}\n\nvoid zeroEvenOddFree(ZeroEvenOdd* obj) {\n \n}",
|
||||
"lang": "Python",
|
||||
"langSlug": "python",
|
||||
"code": "class ZeroEvenOdd(object):\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def even(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def odd(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n ",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
@@ -63,9 +57,15 @@
|
||||
"langSlug": "csharp",
|
||||
"code": "public class ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n public void Zero(Action<int> printNumber) {\n \n }\n\n public void Even(Action<int> printNumber) {\n \n }\n\n public void Odd(Action<int> printNumber) {\n \n }\n}",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "C",
|
||||
"langSlug": "c",
|
||||
"code": "typedef struct {\n int n;\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) {\n ZeroEvenOdd* obj = (ZeroEvenOdd*) malloc(sizeof(ZeroEvenOdd));\n obj->n = n;\n return obj;\n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\n\nvoid zero(ZeroEvenOdd* obj) {\n \n}\n\nvoid even(ZeroEvenOdd* obj) {\n \n}\n\nvoid odd(ZeroEvenOdd* obj) {\n \n}\n\nvoid zeroEvenOddFree(ZeroEvenOdd* obj) {\n \n}",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"41.1K\", \"totalSubmission\": \"73.5K\", \"totalAcceptedRaw\": 41084, \"totalSubmissionRaw\": 73541, \"acRate\": \"55.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"44.7K\", \"totalSubmission\": \"79.1K\", \"totalAcceptedRaw\": 44678, \"totalSubmissionRaw\": 79126, \"acRate\": \"56.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
|
||||
Reference in New Issue
Block a user