[Go] Array and String - Array Partition I
import "sort" func min(x,y int) int{ if x < y { return x } return y } func arrayPairSum(nums []int) int { answer := 0 sort.Slice(nums, func(i,j int) bool { return nums[i] < nums[j] }) //fmt.Printf("%v\n", nums) for i := 0; i < len(nums); i+=2 { answer += min(nums[i], nums[i+1]) } return answer } Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), .....
Go/Leet Code
2022. 4. 10. 02:56