当前位置:网站首页>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
边栏推荐
- DX 的 HLSL 和 GL 的 GLSL的 矩阵构建的行列区别
- Cache control of HTTP
- envoy获取客户端真实IP
- NIO、BIO、AIO
- seven
- Huada 4a0gpio settings
- Cross border e-commerce, early entry and early benefit
- 如何提取网页中的日期?
- Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
- In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
猜你喜欢

In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience

Can AI chat robots replace manual customer service?

Docker 安装 MySQL 8.0,详细步骤

ThreadLocal memory leak

Basic principles of spanning tree protocol

Row and column differences in matrix construction of DX HLSL and GL glsl

Kubevela v1.2 release: the graphical operation console velaux you want is finally here

软件设计的七大原则

Servlet details

What aspects should we start with in the feasibility analysis of dry goods?
随机推荐
Problèmes de concurrence dans l'allocation de mémoire en tas
Shutter precautions for using typedef
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware
Disk structure
Docker installs MySQL 8.0. Detailed steps
Layer 2 and layer 3 forwarding principle based on VLAN
Extend your kubernetes API with aggregated apiserver
How does flutter use the online transcoding tool to convert JSON to model
Short video mall system, how does scroll view adapt to the remaining height of the page
证件照处理
Valueerror: cannot take a larger sample than population when 'replace=false‘
CA Zhouji - the first lesson in 2022 rust
Chapter 10 project stakeholder management
网上立案流程
In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
关于自动控制原理资料更新
揭秘B站,程序员穿女装敲代码,效率更高是真的吗?
Web攻击之CSRF和SSRF
NIO、BIO、AIO
华大04a工作模式/低功耗模式