Day6. Namespace style
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_557._Reverse_Words_in_a_String_III</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
557. Reverse Words in a String III/Program.cs
Normal file
9
557. Reverse Words in a String III/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _557._Reverse_Words_in_a_String_III;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().ReverseWords("God Ding"));
|
||||
}
|
||||
}
|
||||
25
557. Reverse Words in a String III/Solution.cs
Normal file
25
557. Reverse Words in a String III/Solution.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Text;
|
||||
|
||||
namespace _557._Reverse_Words_in_a_String_III;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public string ReverseWords(string s)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if (s[i] == ' ')
|
||||
sb.Append(' ');
|
||||
else
|
||||
{
|
||||
int startIndex = i;
|
||||
while (i < s.Length - 1 && s[i + 1] != ' ')
|
||||
i++;
|
||||
for (int r = i; r >= startIndex; r--)
|
||||
sb.Append(s[r]);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user