vscode-leetcode icon indicating copy to clipboard operation
vscode-leetcode copied to clipboard

561. Array Partition Might be improved

Open AlexndrGetcel opened this issue 3 years ago • 0 comments

🚀 Feature Proposal

Hello, I have recently resolved the task number 561. According to my understanding, the task do not concisely describes a problem. For example, if we were going to find all possible pairs of elements, we should have had cartesian product of them.

Motivation

Description is not clearly describe a final achievable solution.

Contribution

Please consider the code below

public class task561 {
    public static void main(String[] args) {
        int [] nums = {1,4,3,2};


        int lng = nums.length - 1;
        int i = 0, j, l, k = lng;
        int count = Integer.MIN_VALUE, number = 0;

        while (i < lng){
            j = i + 1;
            while (j <= lng){
                while (k >= 0){
                    l = k - 1;
                    while (l >= 0){
                        number = Math.min(nums[i],nums[j]) + Math.min(nums[k], nums[l]);
                        l--;
                    }
                    k--;
                }
                k = lng;
                System.out.println(number);
                j++;
            }
            i++;
        }
    }
}

AlexndrGetcel avatar Oct 12 '22 13:10 AlexndrGetcel