Natural Greedy. Sort the array and pick the medium as target.
class Solution { public: int minMoves2(vector<int>& nums) { int n = nums.size(); if(n == 1) return 0; sort(nums.begin(), nums.end()); int mid = nums[n/2]; int ret = 0; for(auto v : nums) ret += abs(v - mid); return ret; } };