Advertisement
jorupp

https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing

Mar 20th, 2023
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function minOperations(nums: number[]): number {
  2.     let ops = 0;
  3.     let last = 0;
  4.     for(const i of nums) {
  5.         let newNum = i;
  6.         if (i <= last) {
  7.             ops += last+1-newNum;
  8.             newNum = last+1;
  9.         }
  10.         last = newNum;
  11.     }
  12.  
  13.     return ops;
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement