We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1a505a0 commit 3ac56d8Copy full SHA for 3ac56d8
MediumProblems/Reverse Words in a String.cs
@@ -1,17 +1,16 @@
1
namespace LeetCode.MediumProblems
2
{
3
- public class Reverse_Words_in_a_String
+ /// <summary>
4
+ /// https://leetcode.com/problems/reverse-words-in-a-string/
5
+ /// </summary>
6
+ public class ReverseWordsInAString
7
8
public string ReverseWords(string s)
9
- var wordArray = s.Split(" ").Where(x => !string.IsNullOrEmpty(x)).ToArray();
- string returnValue = "";
- for (int i = wordArray.Length - 1; i >= 0; i--)
10
- {
11
- returnValue += $"{wordArray[i].Trim()} ";
12
- }
13
-
14
- return returnValue.TrimEnd();
+ string[] words = s.Split(' ', StringSplitOptions.RemoveEmptyEntries
+ | StringSplitOptions.TrimEntries);
+ Array.Reverse(words);
+ return string.Join(" ", words);
15
}
16
17
-}
+}
0 commit comments