C# solution: char array


  • 0
    B
    public class Solution 
    {
        public string ReverseString(string s) 
        {
            var result = s.ToCharArray();
            var left = 0;
            var right = s.Length - 1;
    
            while(left < right)
            {
                var temp = result[left];
                result[left] = result[right];
                result[right] = temp;
                
                left++;
                right--;
            }
    
            return new string(result);
        }
    }
    

Log in to reply
 

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