【Leetcode周赛】contest-262 (2021年10月11日)
链接:https://leetcode.com/contest/weekly-contest-262
T1: 2032. Two Out of Three
https://leetcode.com/problems/two-out-of-three/
思路:无
T2: 2033. Minimum Operations to Make a Uni-Value Grid
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/
思路:排序找中位数。(为啥能行,其实我也不知道。。)
1 class Solution { 2 public: 3 int minOperations(vector<vector<int>>& grid, int x) { 4 int m = grid.size(), n = grid[0].size(); 5 vector<int> nums(m * n); 6 for (int i = 0; i < m; ++i) { 7 for (int j = 0; j < n; ++j) { 8 nums[j + i * n] = grid[i][j]; 9 } 10 } 11 sort(nums.begin(), nums.end()); 12 int median = nums[(m*n-1)/2]; 13 int res = 0; 14 for (int i = 0; i < nums.size(); ++i) { 15 if (abs(nums[i] - median) % x) { 16 return -1; 17 } 18 int times = abs(nums[i] - median) / x; 19 res += times; 20 } 21 return res; 22 } 23 };
T3: 2034. Stock Price Fluctuation
T4: 2035. Partition Array Into Two Arrays to Minimize Sum Difference
https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/
思路:没有 --- 大坑未补。