Share my C# solution


  • 2
    W
        public class Solution {
        public string ReverseWords(string s) {
               string fin = "";
            for (int i = s.Length - 1; i > -1; i--)
            {
                int temp = 1;
                if (s[i] != 32)
                {
                    while (i - temp >= 0 && s[i - temp] != 32)
                        ++temp;
                    fin += s.Substring(i - temp + 1, temp ) + " ";
                    i -= (temp - 1);
                }
            }
            return fin.TrimEnd(' ');
        }
    }

  • 0
    J

    wow!! perfect


Log in to reply
 

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