You are viewing a single comment's thread. Return to all comments →
Why my code result in TLE? It doesn't seem that the logic is different with some people who have passed
public static long triplets(List<Integer> a, List<Integer> b, List<Integer> c) { List<Integer> listA = a.stream().distinct().sorted().collect(Collectors.toList()); List<Integer> listB = b.stream().distinct().sorted().collect(Collectors.toList()); List<Integer> listC = c.stream().distinct().sorted().collect(Collectors.toList()); long answer = 0; for(int n1 : listB) { long countA = 0; long countC = 0; for(int n2 : listA) { if(n2 <= n1) countA++; else break; } for(int n3 : listC) { if(n3 <= n1) countC++; else break; } answer += countA * countC; } return answer; }
Seems like cookies are disabled on this browser, please enable them to open this website
Triple sum
You are viewing a single comment's thread. Return to all comments →
Why my code result in TLE? It doesn't seem that the logic is different with some people who have passed