We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent daa839f commit da87d8bCopy full SHA for da87d8b
src.save/main/java/g1501_1600/s1551_minimum_operations_to_make_array_equal/Solution.java
@@ -1,16 +1,9 @@
1
package g1501_1600.s1551_minimum_operations_to_make_array_equal;
2
3
-// #Medium #Math #2022_04_11_Time_7_ms_(12.93%)_Space_40.9_MB_(68.22%)
+// #Medium #Math #2022_06_22_Time_0_ms_(100.00%)_Space_41.3_MB_(35.47%)
4
5
public class Solution {
6
public int minOperations(int n) {
7
- int min = 1;
8
- int max = 2 * (n - 1) + 1;
9
- int equalNumber = (max + min) / 2;
10
- int ops = 0;
11
- for (int i = 0; i < n / 2; i++) {
12
- ops += equalNumber - (2 * i + 1);
13
- }
14
- return ops;
+ return (n * n) / 4;
15
}
16
0 commit comments