mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
* test: ReverseStringRecursiveTest * checkstyle: fix formatting * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
22 lines
452 B
Java
22 lines
452 B
Java
package com.thealgorithms.strings;
|
|
|
|
/**
|
|
* Reverse String using Recursion
|
|
*/
|
|
public final class ReverseStringRecursive {
|
|
private ReverseStringRecursive() {
|
|
}
|
|
|
|
/**
|
|
* @param str string to be reversed
|
|
* @return reversed string
|
|
*/
|
|
public static String reverse(String str) {
|
|
if (str.isEmpty()) {
|
|
return str;
|
|
} else {
|
|
return reverse(str.substring(1)) + str.charAt(0);
|
|
}
|
|
}
|
|
}
|