-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution824.cs
40 lines (34 loc) · 997 Bytes
/
Solution824.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
40
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution824
{
/// <summary>
/// 824. Goat Latin - Easy
/// <a href="https://leetcode.com/problems/goat-latin">See the problem</a>
/// </summary>
public string ToGoatLatin(string sentence)
{
var words = sentence.Split(' ');
var vowels = new HashSet<char> { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
var result = new StringBuilder();
for (var i = 0; i < words.Length; i++)
{
var word = words[i];
if (vowels.Contains(word[0]))
{
result.Append(word);
}
else
{
result.Append(word[1..]);
result.Append(word[0]);
}
result.Append("ma");
result.Append('a', i + 1);
result.Append(' ');
}
result.Length--;
return result.ToString();
}
}