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)/数组中第 K 个独一无二的字符串 [kth-distinct-string-in-an-array].html
2022-03-29 12:43:11 +08:00

45 lines
1.8 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><strong>独一无二的字符串</strong>&nbsp;指的是在一个数组中只出现过 <strong>一次</strong>&nbsp;的字符串。</p>
<p>给你一个字符串数组&nbsp;<code>arr</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;,请你返回&nbsp;<code>arr</code>&nbsp;中第&nbsp;<code>k</code>&nbsp;&nbsp;<strong>独一无二的字符串</strong>&nbsp;。如果&nbsp;<strong>少于</strong>&nbsp;<code>k</code>&nbsp;个独一无二的字符串,那么返回&nbsp;<strong>空字符串</strong>&nbsp;<code>""</code>&nbsp;</p>
<p>注意,按照字符串在原数组中的 <strong>顺序</strong>&nbsp;找到第 <code>k</code>&nbsp;个独一无二字符串。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre><b>输入:</b>arr = ["d","b","c","b","c","a"], k = 2
<b>输出:</b>"a"
<strong>解释:</strong>
arr 中独一无二字符串包括 "d" 和 "a"<code>&nbsp;</code>
"d" 首先出现,所以它是第 1 个独一无二字符串。
"a" 第二个出现,所以它是 2 个独一无二字符串。
由于 k == 2 ,返回 "a" 。
</pre>
<p><strong>示例 2:</strong></p>
<pre><b>输入:</b>arr = ["aaa","aa","a"], k = 1
<b>输出:</b>"aaa"
<strong>解释:</strong>
arr 中所有字符串都是独一无二的,所以返回第 1 个字符串 "aaa" 。
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>arr = ["a","b","a"], k = 3
<b>输出:</b>""
<strong>解释:</strong>
唯一一个独一无二字符串是 "b" 。由于少于 3 个独一无二字符串,我们返回空字符串 "" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= arr.length &lt;= 1000</code></li>
<li><code>1 &lt;= arr[i].length &lt;= 5</code></li>
<li><code>arr[i]</code>&nbsp;只包含小写英文字母。</li>
</ul>