We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca4d3b1 commit 5c31801Copy full SHA for 5c31801
src/main/java/com/thealgorithms/stacks/ReverseStringUsingStack.java
@@ -12,21 +12,23 @@ private ReverseStringUsingStack() {
12
* @return reversed string
13
*/
14
15
- public static String reverse(String str) {
+ public static String reverse(String str) {
16
17
Stack<Character> stack = new Stack<>();
18
StringBuilder reversedString = new StringBuilder();
19
-
20
- if(str.isEmpty()) {
+
21
+ if (str.isEmpty()) {
22
return str;
23
}
- for(char i : str.toCharArray()) {
24
+ for (char i : str.toCharArray()) {
25
stack.push(i);
26
- while(!stack.isEmpty()) {
27
+ while (!stack.isEmpty()) {
28
reversedString.append(stack.pop());
29
30
31
return reversedString.toString();
32
33
34
0 commit comments