java solution
\tclass Solution {\n\t\tpublic int largestSumAfterKNegations(int[] nums, int k) {     \n\t\t\tArrays.sort(nums);\n\t\t\tint res = 0;\n\t\t\tint min = 101;\n\t\t
\tclass Solution {\n\t\tpublic int largestSumAfterKNegations(int[] nums, int k) {     \n\t\t\tArrays.sort(nums);\n\t\t\tint res = 0;\n\t\t\tint min = 101;\n\t\t\tfor(int i=0; i<nums.length; ++i){\n\t\t\t\tif(nums[i] < 0 && k > 0){ // flip a negative number, \n\t\t\t\t\tnums[i] = -nums[i];\n\t\t\t\t\tk--; \n\t\t\t\t}\n\t\t\t\tif(nums[i] < min){\n\t\t\t\t\tmin=nums[i]; // find the minimum in the array \n\t\t\t\t}\n\t\t\t\tres += nums[i];\n\t\t\t}\n\t\t\tif(k%2==1) \n\t\t\t\tres -= 2*min;\n\t\t\treturn res;\n\t\t}\n\t}\n\t\t\t// step 1 sort \n\t\t\t// step 2 if there are negative numbers, flip the negatives according to k, and find the minimum in the array \n\t\t\t// step 3 if k%2==1, we will subtract min twice. \n\t\t\t// time O(nlogn)\n\t\t\t// space O(1)
[]