File tree Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Original file line number Diff line number Diff line change 8884
8884
},
8885
8885
{
8886
8886
"cell_type": "code",
8887
- "execution_count": null ,
8887
+ "execution_count": 35 ,
8888
8888
"metadata": {},
8889
- "outputs": [],
8890
- "source": []
8889
+ "outputs": [
8890
+ {
8891
+ "name": "stdout",
8892
+ "output_type": "stream",
8893
+ "text": [
8894
+ "[1, 3, 5, 7, 9, 11]\n",
8895
+ "6\n",
8896
+ "9\n"
8897
+ ]
8898
+ }
8899
+ ],
8900
+ "source": [
8901
+ "# https://leetcode.com/problems/minimum-operations-to-make-array-equal/\n",
8902
+ "\n",
8903
+ "# arr[i] = (2 * i) + 1\n",
8904
+ "\n",
8905
+ "n = 6 \n",
8906
+ "\n",
8907
+ "arr = [''] * n\n",
8908
+ "\n",
8909
+ "for i in range(n):\n",
8910
+ " arr[i] = (2 * i) + 1\n",
8911
+ "\n",
8912
+ "print(arr)\n",
8913
+ "\n",
8914
+ "target = sum(arr)//n \n",
8915
+ "print(target)\n",
8916
+ "\n",
8917
+ "oper_cnt = set()\n",
8918
+ "\n",
8919
+ "for i, val in enumerate(arr): \n",
8920
+ " oper_cnt.add(abs(val - target))\n",
8921
+ "\n",
8922
+ "print(sum(oper_cnt))"
8923
+ ]
8891
8924
},
8892
8925
{
8893
8926
"cell_type": "code",
You can’t perform that action at this time.
0 commit comments