DEV Community

Discussion on: LeetCode with C# - Reverse A String

Collapse
 
joro550 profile image
Mark Davies

When reversing a string manually I've always gone with a for loop:

var reversed = new char[a.Length]
for(int i = a.Length - 1, j = 0; i >= 0 ; i --, j++){
    reversed[j] = a[i];
}

return reversed;
Enter fullscreen mode Exit fullscreen mode

Not sure if this is faster but it's a lot easier to read in my opinion 😄

Collapse
 
charkinsdevelopment profile image
Cory Harkins

That is much much easier on the eyes! I'm bookmarking this solution.