abandon ability able about above absent absorb abstract absurd abuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sort + Two pointer solution | |
// Time: O(nlogn), 1ms | |
// Space: O(1), 36.7mb | |
class Solution { | |
public int twoSumLessThanK(int[] A, int K) { | |
// Sort the array first | |
Arrays.sort(A); | |
// Put pointers at begin/end and shrink | |
int l = 0, r = A.length - 1; |