Created
October 25, 2021 05:04
-
-
Save Shivani13121007/efad38bc40b402522f3594092705bc33 to your computer and use it in GitHub Desktop.
Array Partition I
This file contains 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
class Solution { | |
public int arrayPairSum(int[] nums) { | |
int sum =0; | |
Arrays.sort(nums); | |
// Brute Technique, Accepted, 20ms | |
// for(int i=0;i<nums.length;i+=2) | |
// { | |
// int n = nums[i]; | |
// int m = nums[i+1]; | |
// sum+=Math.min(n,m); | |
// } | |
// Another Approach, Accepted, 11ms | |
for(int i=0;i<nums.length;i+=2) | |
{ | |
int min = nums[i]; | |
sum+=min; | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment