All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 13, 2024
Last updated : July 04, 2024
Related Topics : Math
Acceptance Rate : 82.28 %
sum = (2 * n + 2) * n // 2 mean = (2 * n + 2) / 2 margineToMove = sum(2n+1 - ((2 * n + 2) / 2)) = sum(2n+1 - (n+1)) = sum(n) = (1 + n) * n // 2 number of steps = margineToMove / 2 = (1 + n) * n // 2 // 2 = (n^2 + 1) // 4 = n^2 // 4 = n ** 2 // 4
#define minOperations(n) n * n / 4
int minOperations(int n) {
return n * n / 4;
}
class Solution {
public int minOperations(int n) {
return n * n / 4;
}
}
/**
* @param {number} n
* @return {number}
*/
var minOperations = function(n) {
return n * n / 4;
};
class Solution {
fun minOperations(n: Int): Int {
return n * n / 4;
}
}
class Solution:
def minOperations(self, n: int) -> int:
return n ** 2 // 4
# @param {Integer} n
# @return {Integer}
def min_operations(n)
return n * n / 4;
end
impl Solution {
pub fn min_operations(n: i32) -> i32 {
return n * n / 4;
}
}