Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Write this Code section different
i already posted this , but my post had some mistakes publicĀ classĀ TestĀ { Ā Ā publicĀ staticĀ voidĀ main(String...Ā args)Ā { Ā Ā Ā System.out.println(merge(newĀ int[]Ā {Ā 1,Ā 3,Ā 4,Ā 4,Ā 4,Ā 4,Ā 4,Ā 5Ā },Ā 0)); Ā Ā } Ā Ā Ā Ā publicĀ staticĀ StringĀ merge(int[]Ā ns,Ā intĀ i)Ā { Ā Ā Ā ifĀ (nsĀ ==Ā nullĀ ||Ā iĀ >=Ā ns.length)Ā { Ā Ā Ā Ā returnĀ ""; Ā Ā Ā } ***START HERE with Code "re-writing"*** Ā Ā Ā intĀ p=Ā 1; Ā Ā Ā intĀ n=Ā i; Ā Ā Ā doĀ { Ā Ā Ā p *=Ā ns[i]; Ā Ā Ā n++; Ā Ā Ā }Ā whileĀ (nĀ <Ā ns.lengthĀ &&Ā ns[i]Ā ==Ā ns[n]); Ā Ā Ā returnĀ p+Ā " "Ā +Ā merge(ns, n); Ā Ā } }
4 Respostas
+ 2
Finally had some time to do it :-)
public static String mergeStreams(int[] ns, int i) {
if (ns == null || i >= ns.length) {
return "";
}
Map<Integer, Integer> intMap = Arrays.stream(ns).skip(i).boxed().collect(Collectors.groupingBy(Integer::intValue,
Collectors.reducing(1, (a, b) -> a * b)));
return intMap.values().stream().map(String::valueOf).collect(Collectors.joining(" "));
}
As for performance, it is much slower this way.
+ 1
cool, now i understand it :-)
hmmm i will give it a shot in about 2 hours or so. have to watch something now :-D
0
well this one has mistakes too.
power & next is undefined. :-)
0
yeah... I am such a noob lol ._. I defined them :)
now it should be at least without mistakes