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:
Nihar Kakani
2025-08-27 20:29:04 +05:30
committed by GitHub
parent e78d53d747
commit 27ada8a649
4 changed files with 22 additions and 37 deletions

View File

@@ -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);
}
}
}