当前位置:网站首页>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
边栏推荐
- ThreadLocal内存泄漏问题
- nuScenes——数据集配置过程中遇到图像文件缺失或大小为0时的补救方法
- Basic principles of spanning tree protocol
- Cache control of HTTP
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
- Technology inventory: past, present and future of Message Oriented Middleware
- FANUC机器人_KAREL编程入门学习(1)
- The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
- 问题求解——嵌套列表
- 短视频商城系统,scroll-view如何自适应页面剩余高度
猜你喜欢

Can AI chat robots replace manual customer service?

Ansible basic configuration

虚拟人的产业发展现状

How to automatically remove all . orig files in Mercurial working tree?

YGG recent game partners list

CDN principle

Introduction, installation and use of postman tool

Unable to use the bean introduced into the jar package

FANUC机器人_KAREL编程入门学习(1)

2022-06-10 工作记录--JS-获取到某一日期N天后的日期
随机推荐
干货丨产品的可行性分析要从哪几个方面入手?
How to automatically remove all . orig files in Mercurial working tree?
为什么有的程序员能力一般却能拿到好offer?
[personal experiment report]
Tetris
NIO 零拷贝
Redis hop table
重磅!法大大上榜“专精特新”企业
NIO多路复用之Selector的使用
Data communication foundation - Ethernet port mirroring and link aggregation
理想L9,智能座舱新潮流
2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)
Common voting governance in Dao
try-with-resources 中的一个坑,注意避让
问题求解——嵌套列表
Concurrency of heap memory allocation
Basic principles of spanning tree protocol
Valueerror: cannot take a larger sample than population when 'replace=false‘
堆内存分配的并发问题
Information update on automatic control principle