forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0791-CustomSortString.cs
More file actions
32 lines (27 loc) · 872 Bytes
/
0791-CustomSortString.cs
File metadata and controls
32 lines (27 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//-----------------------------------------------------------------------------
// Runtime: 104ms
// Memory Usage: 22.5 MB
// Link: https://leetcode.com/submissions/detail/364001262/
//-----------------------------------------------------------------------------
using System.Text;
namespace LeetCode
{
public class _0791_CustomSortString
{
public string CustomSortString(string S, string T)
{
var counts = new int[26];
foreach (var ch in T)
counts[ch - 'a']++;
var sb = new StringBuilder();
foreach (var ch in S)
{
sb.Append(ch, counts[ch - 'a']);
counts[ch - 'a'] = 0;
}
for (char ch = 'a'; ch <= 'z'; ch++)
sb.Append(ch, counts[ch - 'a']);
return sb.ToString();
}
}
}