Created
January 14, 2020 18:05
-
-
Save abhilash0001/a57f331244db388117b396e15311b408 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string reverseString(string str) | |
{ | |
return !string.IsNullOrEmpty(str) ? reverse(str) : string.Empty; | |
} | |
private static string reverse(string str) | |
{ | |
var stk = new Stack(); | |
for (int i = 0; i < str.Length; i++) | |
{ | |
stk.push(str[i]); | |
} | |
int k = 0; | |
while(stk.count > 0) | |
{ | |
str[k++] = stk.top(); | |
stk.pop(); | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment