🗓️ One Line Solution, 0ms Beats 100% 🚀
Intuition\n Describe your first thoughts on how to solve this problem. \nI knew that the numbers are in sequence, So my first thoughts is to use the Sum of Arit
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI knew that the numbers are in sequence, So my first thoughts is to use the Sum of Arithmetic Series.\n> Thanks to Carl Friedrich Gauss\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst you need to calculate the sum of all Odd numbers from 1 to 2*n-1 \nwe got `sum`= `n^2`\n\n![Capture1.PNG](https://assets.leetcode.com/users/images/9f66fa53-6168-42f3-848b-d98bcf9a53ec_1677431611.3710175.png)\n\nThen the `average` = `sum/n` = `n`, so the `average` it\'s just `n`\n\n![Capture2.PNG](https://assets.leetcode.com/users/images/866238a2-20d0-4190-8603-1910aae722e7_1677431730.8526685.png)\n\nThe result will be just the sum of all numbers: \n{ `average - i` with `(i=1 ; i<=n ; i+=2)` }\n- If you use the Sum of Arithmetic Series it will be like this : \n![Capture3.PNG](https://assets.leetcode.com/users/images/04cef7cd-c94d-41fd-9ad8-4bc706f81aaa_1677434707.2776978.png)\nwith this relation you need to use `Math.ceil()` \nCode :`return (int)Math.ceil(n*(n/2.0+0.5)-(n/2.0+0.5)*(n/2.0+0.5));`\n\n- Here is another relation that is simple and does not use `Math.ceil` :\n![Capture5.PNG](https://assets.leetcode.com/users/images/82d8d307-ca00-4c74-98e0-43e19cadf4f2_1677780064.6279993.png)\n\nthis relation works because we know that the numbers after the comma will be removed automatically without the need to use `Math.floor()`\nCode : `return (n*n)/4;`\n\n# Complexity\n- Time complexity: O(1)\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\n    public int minOperations(int n) {\n        //You can call me Gauss\n        return (n*n)/4;\n    }\n}\n```
['Python', 'C++', 'Java', 'JavaScript']