当前位置:网站首页>Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
2022-06-24 22:36:00 【Review of the white speed Dragon King】
Ideas :
Look in the opposite direction
use sortedlist Add , then bisectleft Find something smaller than yourself
src:
from sortedcontainers import SortedList
class Solution:
def countSmaller(self, nums: List[int]) -> List[int]:
n = len(nums)
s = SortedList()
ans = [0] * n
# Reverse traversal
for i in range(n - 1, -1, -1):
# Find something smaller than your right
less = s.bisect_left(nums[i])
# Put it in the answer
ans[i] = less
# Add yourself
s.add(nums[i])
return ans
summary :
sortedlist + bisectleft The combination of
边栏推荐
- 【軟件工程】期末重點
- Information update on automatic control principle
- How to grab the mobile phone bag for analysis? Fiddler artifact may help you!
- Fanuc robot_ Introduction to Karel programming (1)
- Virtual private network foundation
- Introduction, installation and use of postman tool
- 【软件工程】期末重点
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
- Tetris
- ThreadLocal memory leak
猜你喜欢
How to solve the problem that the computer suddenly can't connect to WiFi
Ansible basic configuration
leetcode:55. Jumping game [classic greed]
VRRP skills topic
如何比较两个或多个分布:从可视化到统计检验的方法总结
Genesis公链与美国一众加密投资者齐聚Consensus 2022
Ideal L9, new trend of intelligent cockpit
Tetris
Information update on automatic control principle
Docker installs redis-5.0.12. Detailed steps
随机推荐
华大4A0GPIO设置
Genesis public chain and a group of encryption investors in the United States gathered in consensus 2022
Creating files, recursively creating directories
第二批入围企业公示!年度TOP100智能网联供应商评选
详细了解关于sentinel的实际应用
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
Servlet详解
Row and column differences in matrix construction of DX HLSL and GL glsl
L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)
ThreadLocal内存泄漏问题
CDN principle
问题求解——嵌套列表
Cache control of HTTP
堆内存分配的并发问题
In the era of industrial Internet, there is no Internet in the traditional sense
Redis-跳表
学习笔记23--多传感器信息融合基础理论(上)
DX 的 HLSL 和 GL 的 GLSL的 矩阵构建的行列区别
interrupt、interrupted 、isInterrupted 区别