text: // Hi, I'm Yanzhan. I'm interested in all kinds of algorithmic problems. Also, I'm fascinated with javascript. If you want to learn more about programming problems and javascript, please visit my Youtube Channel (https://www.youtube.com/channel/UCDkz-__gl3frqLexukpG0DA?view_as=subscriber), Twitter Account (https://twitter.com/YangYanzhan), GitHub Repo (https://github.com/yangyanzhan/code-camp) or HomePage (https://yanzhan.site/).
  
  // 开始分析
  // 1. 归并排序。
  // 结束分析
  
  // 开始编码
  
  /**
   * @param {number[]} nums
   * @return {number}
   */
  
  var reversePairs = function(nums) {
      var res = 0;
      function mergeSort(nums, i, j) {
          if (i >= j) {
              return;
          }
          var k1 = Math.floor((i + j) / 2);
          var k2 = k1 + 1;
          mergeSort(nums, i, k1);
          mergeSort(nums, k2, j);
          var sorted = [], idx1 = i, idx2 = k2;
          while (idx1 <= k1 && idx2 <= j) {
              var num1 = nums[idx1], num2 = nums[idx2];
              if (num1 <= num2) {
                  sorted.push(num1);
                  idx1++;
              } else {
                  sorted.push(num2);
                  res += k1 - idx1 + 1;
                  idx2++;
              }
          }
          for (var idx = idx1; idx <= k1; idx++) {
              sorted.push(nums[idx]);
          }
          for (var idx = idx2; idx <= j; idx++) {
              sorted.push(nums[idx]);
          }
          for (var idx = i; idx <= j; idx++) {
              nums[idx] = sorted[idx - i];
          }
      }
      mergeSort(nums, 0, nums.length - 1);
      return res;
  };
  