151. Reverse Words in a String

151. Reverse Words in a String Leetcode Qn :
   
  

public class Solution {
    public string ReverseWords(string str) {
     // Split the input string by whitespace into an array of words
        string[] words = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        // Reverse the array of words
        Array.Reverse(words);

        // Join the reversed words back into a single string
        string reversedString = string.Join(" ", words);

        return reversedString;
}
}
  

Comments