C# Solution (Reverse String)


  • 0
    A
    public string ReverseString(string s) {
            if (String.IsNullOrEmpty(s))
                    return s;
                else
                {
                    char[] wordChars = s.ToCharArray();
                    char[] reversedArray = new char[wordChars.Length];
                    int reversedArrayIndex = wordChars.Length - 1;
                    for (int i = 0; i < wordChars.Length; i++)
                    {
                        reversedArray[reversedArrayIndex] = wordChars[i];
                        reversedArrayIndex--;
                    }
                    s = new string(reversedArray);
                    return s;
                }
        }
    

Log in to reply
 

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