4 ms·
The LeetCode version doesn't require linear time, and caps the number of elements to 10^5, so the brute-force O(n^2) time solution seems perfectly acceptable.
by kd5bjo 4y ago
The LeetCode version doesn't require linear time, and caps the number of elements to 10^5, so the brute-force O(n^2) time solution seems perfectly acceptable.
- dullcrisp 4y agoTried it with a simple loop, got time limit exceeded unfortunately.