C# Simple straight fwd solution - not the most efficient


  • 1
    V
    public class Solution {
        public string ReverseWords(string s) {
            if(s == null || s.Length <= 0)
                return string.Empty;
            var words = s.Split(' ');
            StringBuilder sb = new StringBuilder();
            foreach(string str in words)
            {
                char[] c = str.ToCharArray();
                sb.Append(string.Join("", c.Reverse()));
                sb.Append(" ");
            }
            return sb.ToString().Trim();
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.