Editorial solution is o(n*n) in worst case


#1

Editorial solution time complexity is O(n*n). Please correct me if I am wrong


public class Solution {
    public int threeSumClosest(ArrayList<Integer> arr, int target) {
        Collections.sort(arr);
        int totalSum = Integer.MAX_VALUE, curSum,j,k;
        for(int i =0 ;i<arr.size()-2;i++) {
            j = i+1; k =arr.size()-1;
            while(j < k) {
                curSum = arr.get(i) + arr.get(j) + arr.get(k) ;
                if(curSum == target) return target;
                if(curSum < target) j++;
                else k--;
                if(Math.abs(target-curSum) < (totalSum == Integer.MAX_VALUE ? Integer.MAX_VALUE : Math.abs(totalSum - target))) {
                    totalSum = curSum;
                }
            }
        }
        return totalSum;
    }
}