Java Clean Solution & explanation
Please \uD83D\uDD3C upvote this post if you find the answer useful & do comment about your thoughts \uD83D\uDCAC\n\n## Explanation\n\nThis is the most clean sol
**Please** \uD83D\uDD3C **upvote this post if you find the answer useful & do comment about your thoughts** \uD83D\uDCAC\n\n## Explanation\n\nThis is the most clean solution in Java which calculates number of operations along with array updation of the operations to be made.\n\n- At first we check whether the given array contains only one element and return 0\n- Next, we loop for N times to find minOperations\n- We must compare current element and next element, hence we need to make sure that the next element exists\n- Now we check if current element is greater than next element and only then we need to perform operations.\n- We find the number of operations by taking the difference of current and next element and add 1 to make sure that we maintain increasing order in array\n- We also update the array itself, to make sure that we check the next elements properly\n- Finally we return the answer\n- Time complexity - O(N)\n- Space complexity - O(1)\n\n## Java Code\n\n```\nclass Solution {\n    public int minOperations(int[] nums) {\n        if(nums.length<=1) {\n            return 0;\n        }\n        int ans = 0;\n        for(int i=0; i<nums.length; i++) {\n            if(i+1>=nums.length) {\n                return ans;\n            }\n            if(nums[i+1] <= nums[i]) {\n                ans += nums[i] - nums[i+1] + 1;\n                nums[i+1] += nums[i] - nums[i+1] + 1;\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']