五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 775. Global and Local Inversions

2023-04-22 08:43 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an integer array?nums?of length?n?which represents a permutation of all the integers in the range?[0, n - 1].

The number of?global inversions?is the number of the different pairs?(i, j)?where:

  • 0 <= i < j < n

  • nums[i] > nums[j]

The number of?local inversions?is the number of indices?i?where:

  • 0 <= i < n - 1

  • nums[i] > nums[i + 1]

Return?true?if the number of?global inversions?is equal to the number of?local inversions.

?

Example 1:

Input: nums = [1,0,2]

Output: true

Explanation: There is 1 global inversion and 1 local inversion.

Example 2:

Input: nums = [1,2,0]

Output: false

Explanation: There are 2 global inversions and 1 local inversion.

這里面local的就一定是global的,所以如果要返回false就是當(dāng)存在num[i]>num[j];

同時i+2<=j;

我們保存一個max,讓max去跟目前的j去比對,即可;

?

Constraints:

  • n == nums.length

  • 1 <= n <= 105

  • 0 <= nums[i] < n

  • All the integers of?nums?are?unique.

  • nums?is a permutation of all the numbers in the range?[0, n - 1].



Runtime:?1 ms, faster than?100.00%?of?Java?online submissions for?Global and Local Inversions.

Memory Usage:?51.6 MB, less than?70.61%?of?Java?online submissions for?Global and Local Inversions.


LeetCode 775. Global and Local Inversions的評論 (共 條)

分享到微博請遵守國家法律
那坡县| 磴口县| 重庆市| 青海省| 黄浦区| 新泰市| 五台县| 神池县| 闽清县| 榆树市| 五台县| 武清区| 孙吴县| 炎陵县| 麻城市| 平邑县| 全南县| 禄劝| 涞源县| 子长县| 师宗县| 县级市| 泰州市| 唐河县| 正蓝旗| 三河市| 崇文区| 揭东县| 长岭县| 聂荣县| 凤山市| 安顺市| 赣榆县| 肥西县| 南通市| 武城县| 吉隆县| 青浦区| 昌黎县| 胶州市| 萨迦县|