mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 11:21:42 +08:00
add leetcode problem-cn part1
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<p>给你一个类:</p>
|
||||
|
||||
<pre>
|
||||
class FooBar {
|
||||
public void foo() {
|
||||
for (int i = 0; i < n; i++) {
|
||||
print("foo");
|
||||
}
|
||||
}
|
||||
|
||||
public void bar() {
|
||||
for (int i = 0; i < n; i++) {
|
||||
print("bar");
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>两个不同的线程将会共用一个 <code>FooBar</code> 实例:</p>
|
||||
|
||||
<ul>
|
||||
<li>线程 A 将会调用 <code>foo()</code> 方法,而</li>
|
||||
<li>线程 B 将会调用 <code>bar()</code> 方法</li>
|
||||
</ul>
|
||||
|
||||
<p>请设计修改程序,以确保 <code>"foobar"</code> 被输出 <code>n</code> 次。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 1
|
||||
<strong>输出:</strong>"foobar"
|
||||
<strong>解释:</strong>这里有两个线程被异步启动。其中一个调用 foo() 方法, 另一个调用 bar() 方法,"foobar" 将被输出一次。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 2
|
||||
<strong>输出:</strong>"foobarfoobar"
|
||||
<strong>解释:</strong>"foobar" 将被输出两次。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 1000</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user