topic:
6324. Maximize the great value of the array.md
Give you a bidding 0 Started integer array nums 。You need to nums Re -arrange into a new array perm 。
definition nums of Great value To satisfy 0 <= i < nums.length and perm[i] > nums[i] of下标数目。
Please return to re -arrangement nums 后of maximum Great value。
Exemplary example 1:
enter:nums = [1,3,5,2,1,3,1]
Output:4
explain:A optimal arrangement scheme is perm = [2,5,1,3,3,1,1] 。
The bidding is 0, 1, 3 and 4 Place,All perm[i] > nums[i] 。So we return 4 。
Thought:
Three ways to think about this question:
The first is Tian Ji horse racing(I am): InumsContinuously reappear,Advance numbers,Then compare(time out)
Then there is a double pointer-Hash table:
每个元素只能被bigof元素指向一次(for example5Compare3big,3Can’t follow4对Compare了)
Two pointers point to the tail element at the same time,whenleft not less than rightof时候,left–。
else left– right– Counter– count ++
Last returncount
灵神ofTian Ji horse racing:
sort后直接在原数组上面找Comparewhen前元素bigof元素
Code:
1 | class Solution: |
1 | class Solution: |
1 | class Solution: |