擅长:python、mysql、java
<p>以下是我的解决方案(见评论):</p>
<pre class="lang-py prettyprint-override"><code>def validate_soup(s: str, chars: str)-> bool:
d = {}
for c in chars:
count = d.get(c, 0)
d[c] = count + 1
for c in s:
count = d.get(c, 0)
if count <= 0:
return False
d[c] = count - 1
return True
</code></pre>