当前位置:网站首页>1331. Array sequence number conversion
1331. Array sequence number conversion
2022-07-28 11:27:00 【51CTO】
Give you an array of integers arr , Please replace each element in the array with their ordinal number after sorting .
The serial number represents how big an element is . The rules for serial numbers are as follows :
- The serial number from 1 Numbered starting .
- The bigger an element is , So the bigger the serial number . If two elements are equal , So they have the same serial number .
- The serial number of each number should be as small as possible .
Input :arr = [40,10,20,30]
Output :[4,1,2,3]
explain :40 It's the biggest element . 10 It's the smallest element . 20 It's the second smallest number . 30 It's the third smallest number .
Explain :
After de reordering , Use a dictionary to record the sequence number of each number .
There are two small details ,
The first detail is set It can also be used. sorted Function order .
sorted Function description : according to iterable Returns a new sorted list .
Any iteratable object can be used sorted Sort , The result is a new sort list .
The second detail is enumerate You can specify the value from which the sequence number starts ,enumerate(sorted_arr,1) This is from 1 Start counting .
边栏推荐
- Two point, three point, 01 point plan [bullet III]
- 接口测试的作用
- C语言使用二重指针实现简单工厂模式(多态)
- 开源汇智创未来 | 2022开放原子全球开源峰会OpenAtom openEuler分论坛圆满召开
- Postgres overview
- Do you want to enroll in class for advanced soft exam
- 【C语言】的%*d、%.*s等详解:「建议收藏」
- What is WordPress
- DHCP experiment demonstration (Huawei switch device configuration)
- 什么样的知识付费系统功能,更有利于平台与讲师发展?
猜你喜欢
![[MySQL from introduction to proficiency] [advanced chapter] (x) MyISAM's indexing scheme & advantages and disadvantages of indexing](/img/f4/e04bf0f8f0866ea9db0615f0e5e1c4.png)
[MySQL from introduction to proficiency] [advanced chapter] (x) MyISAM's indexing scheme & advantages and disadvantages of indexing

Encryption defect of icloud Keychain in Apple mobile phone

技术分享| 快对讲综合调度系统

本地化、低时延、绿色低碳:阿里云正式启用福州数据中心

No swagger, what do I use?

「学习笔记」树状数组

五面阿里技术专家岗,已拿offer,这些面试题你能答出多少
![[JS advanced] JS functions, overloads, anonymous functions, scopes and scope chains_ 03](/img/50/754f7915ee4b2e04fdd21ae68130c6.png)
[JS advanced] JS functions, overloads, anonymous functions, scopes and scope chains_ 03

Learn these analysis methods and models, and no longer have no ideas when encountering problems

The solution of PHP sending mobile MAS SMS garbled code
随机推荐
Install SSL Certificate in Litespeed web server
What's the secret of creating a popular short video?
RHEL 6.4 安装svn和apache
Purchase, sale and inventory software suitable for small and medium-sized enterprises to solve five major problems
关于结构体指针函数的返回值传递给结构体指针的理解
JS - modify the key name of the object in the array
ZBrush 2022软件安装包下载及安装教程
Encryption defect of icloud Keychain in Apple mobile phone
Leetcode:981. time based key value storage [trap of iteration for: on]
PHP检测url网址链接是否正常可访问
Do data analysis, do you still not understand RFM analysis method (model)?
What is WordPress
Use the common union and pointer to test the size end
重新刷新你对Redis集群的理解
C language uses double pointer to realize simple factory mode (polymorphism)
go status.go 状态码定义
LiteSpeed Web服务器中安装SSL证书
什么是WordPress
Do you want to enroll in class for advanced soft exam
Learning notes tree array