-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0824-GoatLatin.cs
39 lines (34 loc) · 1.11 KB
/
0824-GoatLatin.cs
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
33
34
35
36
37
38
39
//-----------------------------------------------------------------------------
// Runtime: 84ms
// Memory Usage: 23.4 MB
// Link: https://leetcode.com/submissions/detail/335026204/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
namespace LeetCode
{
public class _0824_GoatLatin
{
public string ToGoatLatin(string S)
{
var vowels = new HashSet<char>() { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
var wordIndex = 1;
var sb = new StringBuilder();
foreach (var word in S.Split())
{
if (vowels.Contains(word[0]))
sb.Append(word);
else
{
sb.Append(word.Substring(1));
sb.Append(word.Substring(0, 1));
}
sb.Append("ma");
sb.Append(new string('a', wordIndex++));
sb.Append(" ");
}
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
}
}