We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I see everybody posted solutions with 2 for loops. I did mine with just one in Java:
// Complete the countApplesAndOranges function below.staticvoidcountApplesAndOranges(ints,intt,inta,intb,int[]apples,int[]oranges){intappleCount=0;intorangeCount=0;for(inti=0;i<Math.max(apples.length,oranges.length);i++){appleCount+=isFruitInRange(apples,i,s,t,a);orangeCount+=isFruitInRange(oranges,i,s,t,b);}System.out.println(appleCount);System.out.println(orangeCount);}privatestaticintisFruitInRange(intfruits[],inti,ints,intt,inttreePos){returni<fruits.length&&(treePos+fruits[i])>=s&&(treePos+fruits[i])<=t?1:0;}
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
I see everybody posted solutions with 2 for loops. I did mine with just one in Java: