当前位置:网站首页>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 .
边栏推荐
- DHCP experiment demonstration (Huawei switch device configuration)
- Installation points and precautions of split angle probe
- 什么是WordPress
- PKG packaging node project
- Make a virtual human with zego avatar | virtual anchor live broadcast solution
- 关于结构体指针函数的返回值传递给结构体指针的理解
- 【MySQL从入门到精通】【高级篇】(九)InnoDB的B+树索引的注意事项
- JS - modify the key name of the object in the array
- 构建快捷开发IDE:VisualSVN+Sublime+Visual Studio 2013+QuickEasyFTPServer
- C language uses double pointer to realize simple factory mode (polymorphism)
猜你喜欢

Summary of the second semester of junior year

Two dimensional prefix and

Bc35 NB module at instruction development summary
![[MySQL from introduction to proficiency] [advanced chapter] (IX) precautions for InnoDB's b+ tree index](/img/dc/2c11852929cc2ad4a2e44b87e6f812.png)
[MySQL from introduction to proficiency] [advanced chapter] (IX) precautions for InnoDB's b+ tree index

用手机对电脑进行远程关机

什么是WordPress

小水滴2.0网站导航网模板

Zero code | easily realize data warehouse modeling and build Bi Kanban
![Leetcode:981. time based key value storage [trap of iteration for: on]](/img/87/759594104d61bf787693544dd7152d.png)
Leetcode:981. time based key value storage [trap of iteration for: on]

Technology sharing | quick intercom integrated dispatching system
随机推荐
Technology sharing | quick intercom integrated dispatching system
擦黑板特效表白H5源码+非常浪漫/附BGM
什么是WordPress
Under the platform driven platform, the "dev- > dev.of_node" of the formal parameter dev in the probe function Understanding of
Cortex-M内核管理全局中断的三种方式
本地化、低时延、绿色低碳:阿里云正式启用福州数据中心
「学习笔记」树状数组
[MySQL] MySQL error "error 2006 (HY000): MySQL server has gone away"
JWT 登录认证 + Token 自动续期方案,写得太好了!
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
Explanation of JDBC classes
DHCP实验演示(Huawei交换机设备配置)
Zero code | easily realize data warehouse modeling and build Bi Kanban
不用Swagger,那我用啥?
What is WordPress
C语言使用二重指针实现简单工厂模式(多态)
Make a virtual human with zego avatar | virtual anchor live broadcast solution
go status.go 状态码定义
Use the statement object to execute DDL statements to create tables
机器学习强基计划0-5:为什么学习的本质是泛化能力?