Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a8a3abd

Browse files
committed
Added README.md file for Sort Characters By Frequency
1 parent fa8bdd2 commit a8a3abd

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/sort-characters-by-frequency">Sort Characters By Frequency</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>Given a string <code>s</code>, sort it in <strong>decreasing order</strong> based on the <strong>frequency</strong> of the characters. The <strong>frequency</strong> of a character is the number of times it appears in the string.</p>
2+
3+
<p>Return <em>the sorted string</em>. If there are multiple answers, return <em>any of them</em>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> s = &quot;tree&quot;
10+
<strong>Output:</strong> &quot;eert&quot;
11+
<strong>Explanation:</strong> &#39;e&#39; appears twice while &#39;r&#39; and &#39;t&#39; both appear once.
12+
So &#39;e&#39; must appear before both &#39;r&#39; and &#39;t&#39;. Therefore &quot;eetr&quot; is also a valid answer.
13+
</pre>
14+
15+
<p><strong class="example">Example 2:</strong></p>
16+
17+
<pre>
18+
<strong>Input:</strong> s = &quot;cccaaa&quot;
19+
<strong>Output:</strong> &quot;aaaccc&quot;
20+
<strong>Explanation:</strong> Both &#39;c&#39; and &#39;a&#39; appear three times, so both &quot;cccaaa&quot; and &quot;aaaccc&quot; are valid answers.
21+
Note that &quot;cacaca&quot; is incorrect, as the same characters must be together.
22+
</pre>
23+
24+
<p><strong class="example">Example 3:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> s = &quot;Aabb&quot;
28+
<strong>Output:</strong> &quot;bbAa&quot;
29+
<strong>Explanation:</strong> &quot;bbaA&quot; is also a valid answer, but &quot;Aabb&quot; is incorrect.
30+
Note that &#39;A&#39; and &#39;a&#39; are treated as two different characters.
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>5</sup></code></li>
38+
<li><code>s</code> consists of uppercase and lowercase English letters and digits.</li>
39+
</ul>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /