@restive tulip
#Need Help With Java method code
1 messages · Page 1 of 1 (latest)
<@&934250633580658788>
ok
Question: does your solution have to be the most efficient?
not really
i know you can do it in one line someone told me but its stuff we havent learned
public static int[] merge(int[] a, int[] b){
int IndexInResult = 0, IndexA = 0, IndexB = 0;
int [] FinalOutcome = new int[b.length + a.length];
while((b.length > IndexB) || (a.length > IndexA))
{
if(IndexA > a.length)
{
FinalOutcome[IndexInResult] = b[IndexB];
IndexB++;
}
else if(IndexB > b.length)
{
FinalOutcome[IndexInResult] = a[IndexA];
IndexA++;
}
else if(b[IndexB] > a[IndexA])
{
FinalOutcome[IndexInResult] = a[IndexA];
IndexA++;
}
else if(b[IndexB] < a[IndexA])
{
FinalOutcome[IndexInResult] = b[IndexB];
IndexB++;
}
IndexInResult++;
}
return FinalOutcome;
}
i did this so far
Are you allowed to use Arrays.sort(arr);
Nope someone already asked me that lol
Lol dang
yeah idk
One moment please I'm actually about to wash the dishes 😅 but I'm not ignoring you! I will be back
ok!
I'm back!
Hi i was actually able to figure this one out
im just stuck on this one now
its part of that its just the last method
Oh nice! I actually made my own solution too lol 😅