mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Migrate recursive reverse string method and tests to ReverseString (#6504)
* Migrate recursive reverse string method and tests to ReverseString - Moved recursive reverse method from ReverseStringRecursive.java to ReverseString.java - Moved tests from ReverseStringRecursiveTest.java to ReverseStringTest.java - Deleted old ReverseStringRecursive files * Fix formatting for ReverseStringTest.java as per clang-format linter
This commit is contained in:
@@ -86,4 +86,17 @@ public final class ReverseString {
|
||||
}
|
||||
return reversedString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the String using Recursion
|
||||
* @param str string to be reversed
|
||||
* @return reversed string
|
||||
*/
|
||||
public static String reverseStringUsingRecursion(String str) {
|
||||
if (str.isEmpty()) {
|
||||
return str;
|
||||
} else {
|
||||
return reverseStringUsingRecursion(str.substring(1)) + str.charAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user