Reverse a string in Java without using any inbuilt function
- Time Complexity : O(n)
- Space Complexity : O(n)
public static String reverseWord(String str)
{
// Reverse the string str
int n = str.length();
String temp="" ;
for(int i=n-1;i>=0;i--){
temp+=str.charAt(i);
}
return temp;
}
No comments:
Post a Comment