Skip to content
Advertisement

Tag: recursion

reverse a string using recursion with java

I am trying to write a recursion to reverse a String.This is my approach. I dont get why when it reaches the base case, where my a is already empty but I am still able to print out the reversed string. Answer you are not implementing any recursion, you just replaced two halves of a string.

How does parameters of a method get stored in stack during a recursive call?

I was doing a leetcode question https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ and I am confused on how parameters for a method get stored during a recursive call. If a node gets visited, I wanted to save it’s state that it was visited. When I send two variables, when the stack is getting unwinded the updated variable values are being lost. But if I send

How to tidying my Java code because it has too many looping [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago. Improve this question I have a Node class used to represent a tree structure. Within this class, I’ve defined a print method that

How do I approach this recursively in Java?

In this program I need to get input from the user that indicates the length of the numbers with this quality: The number should be prime and if you delete each digit from the right the number that is left should still be prime. i.e. 2399 is such a number. Because 2399 is prime, and also 239, and 23, and

Advertisement