#Recursive Method to find if 2 numbers have the same length
117 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @odd axle! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
you're duplicating code there, the part before isSameLen is the same as after
you need to return the result of isSameLen, but you're overwriting e in most cases
you don't need a lot of this
you just need the first if, else if, then after that you can just return isSameLen(...); directly
how do i do that
just remove stuff
k
you have everything you need, the problem is you have too much that's breaking it
.
like this?
no, keep the first 2 if/elses
e is unnecessary
the last if check is unnecessary, do return isSameLen(...); unconditionally
like this?
you're overcomplicating it
please
read what im saying exactly
you need exactly 1 if, 1 else if, and the 3 returns
yes
this one returned true
remove boolean e
i did
do you want an explanation of this
the if and else if are the base cases of the recursion, they say where to stop
we use recursion to cut off 1 digit at a time here, so the base case is when either number gets down to 0
if both numbers get down to 0 at the same time, they're the same length; that's what the first if does
if one number gets down to 0 but the other isn't yet, they aren't the same length; that's what the else if does
ahhhh
otherwise, we haven't reached that base case yet; cut off a digit of each (the / 10) and check again
yes
do u think u could help me with another question if u dont mind?
sure
ok so
its a recursive method
where it gets a int[] of 0's and 1's
as parameter
the most left index
the most right index
and a int
(recursive method btw, recursion is a noun, recursive is an adjective, recurse is a verb)
that represents an index
my word isnt opening
hold on
ah basically
it return the streak of 1's
around the index int
so like lets say we have
0111110
and the int is 4
it should return 5
if the int lands on a zero its an instant false
does it need to be recursive?
yes
yes
its a bonus question
that's going to be kinda cursed as a single method
if i can do that i will be ready for my test
i guess you'd have to do counting forwards and backwards
lemme send u the word file
scroll all the way down on it
my office isnt working rn idk why
can't you just send it as text
not letting me open it
lemme try to fix my office then just wait a sec
fixed
on the right is what it is supposed to return
idk why the fuck the left and right is there
ohhhh i see
you're supposed to count from left to right, decrementing left and k
that's how the recursion is achieved
actaully probably more complicated than this
im figuring i need a count int
oh wait
what if
i move the int left
to the first 0 left of the int k
and right
ahhhh
something like this
then if A[left] is a zero i stop moving it
and i check from k
there's an issue with having 1s before k there i guess
well i can see why it's a bonus question lol
first of all
if (A[k] == 0) return false;
i mean return 0
do u think u know how to do this
im really tired right now lol, nothing's coming to mind
i think figuring out some base cases would help
what do u mean?