1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/动物收容所 [animal-shelter-lcci].html
2022-03-29 12:43:11 +08:00

30 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>动物收容所。有家动物收容所只收容狗与猫,且严格遵守&ldquo;先进先出&rdquo;的原则。在收养该收容所的动物时,收养人只能收养所有动物中&ldquo;最老&rdquo;(由其进入收容所的时间长短而定)的动物,或者可以挑选猫或狗(同时必须收养此类动物中&ldquo;最老&rdquo;的)。换言之,收养人不能自由挑选想收养的对象。请创建适用于这个系统的数据结构,实现各种操作方法,比如<code>enqueue</code><code>dequeueAny</code><code>dequeueDog</code><code>dequeueCat</code>。允许使用Java内置的LinkedList数据结构。</p>
<p><code>enqueue</code>方法有一个<code>animal</code>参数,<code>animal[0]</code>代表动物编号,<code>animal[1]</code>代表动物种类,其中 0 代表猫1 代表狗。</p>
<p><code>dequeue*</code>方法返回一个列表<code>[动物编号, 动物种类]</code>,若没有可以收养的动物,则返回<code>[-1,-1]</code></p>
<p><strong>示例1:</strong></p>
<pre><strong> 输入</strong>
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueCat&quot;, &quot;dequeueDog&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [], [], []]
<strong> 输出</strong>
[null,null,null,[0,0],[-1,-1],[1,0]]
</pre>
<p><strong>示例2:</strong></p>
<pre><strong> 输入</strong>
[&quot;AnimalShelf&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;enqueue&quot;, &quot;dequeueDog&quot;, &quot;dequeueCat&quot;, &quot;dequeueAny&quot;]
[[], [[0, 0]], [[1, 0]], [[2, 1]], [], [], []]
<strong> 输出</strong>
[null,null,null,null,[2,1],[0,0],[1,0]]
</pre>
<p><strong>说明:</strong></p>
<ol>
<li>收纳所的最大容量为20000</li>
</ol>