add new file: c# reverse words in string

pull/1215/head
katkat825 2023-06-30 12:51:21 -04:00
parent d1f7426a61
commit b1333bcad6
2 changed files with 4 additions and 3 deletions

View File

@ -30,6 +30,7 @@ To run the `.cs` file, kindly use [.Net Finddle](https://dotnetfiddle.net/)
- [Palindrome](src/Strings/palindrome.cs) - [Palindrome](src/Strings/palindrome.cs)
- [Trie](src/Strings/trie.cs) - [Trie](src/Strings/trie.cs)
- [Character Limit](src/Strings/character-limit.cs) - [Character Limit](src/Strings/character-limit.cs)
- [Reverse Words in String](src/Strings/reverse-words-in-string.cs)
## Search ## Search

View File

@ -1,8 +1,6 @@
using System; using System;
//Reverse the order of the words in a given string //Time Complexity: O(n)
//Example: "Hello World" becomes "World Hello"
namespace Algorithms.Strings namespace Algorithms.Strings
{ {
public class ReverseWordsInString public class ReverseWordsInString
@ -15,6 +13,8 @@ namespace Algorithms.Strings
Console.WriteLine(ReverseWords(originalString)); Console.WriteLine(ReverseWords(originalString));
} }
//Reverse the order of the words in a given string
//Example: "Hello World" becomes "World Hello"
public static string ReverseWords(string input) public static string ReverseWords(string input)
{ {
string[] words = input.Split(' '); string[] words = input.Split(' ');