Python | Leetcode Python题解之第315题计算右侧小于当前元素的个数
创始人
2024-11-14 08:06:35
0次

题目:

题解:

import numpy as np from bisect import bisect_left  class Solution:     max_len =  10000     c = []     buckets = []      def countSmaller(self, nums: List[int]) -> List[int]:         self.c = [0 for _ in range(len(nums) + 5)]         counts = [0 for _ in range(len(nums))]         nums = self.discretization(nums)         for i in range(len(nums) - 1, -1, -1):             num = nums[i]             counts[i] = self.query(num-1)             self.updateC(num)         return counts      def updateC(self, pos):         while pos < len(self.c):             self.c[pos] += 1             pos += self.lowbit(pos)      def lowbit(self, x):         """获取更新范围"""         return x & (-x)      def query(self, pos):         """查询前缀和"""         val = 0         while pos > 0:             val += self.c[pos]             pos -= self.lowbit(pos)         return val      def getMappingList(self, nums):         """列表去重排序"""         return list(sorted(set(nums)))      def discretization(self, nums):         """将nums进行离散化变换"""         mapping = self.getMappingList(nums)         return [bisect_left(mapping, num) + 1 for num in nums]

相关内容

热门资讯

微扑克辅助器!德州平台有没有挂... 您好:德州平台有没有挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
AApoker透视挂!wepo... 很多人使用云端 AI 时,都担心wepoker透视挂是真的吗、内部资料上传带来隐私风险。这款本地运行...
WePoKer透视!wepok... WePoKer透视!wepoker如何拿到好牌,分享透视多功能软件APP模板;近期一款 AI 黑科技...
红龙扑克透视挂!德扑之星规律,... 红龙扑克透视挂!德扑之星规律,解迷透视挂多功能插件APP法门是一款可以让一直输的玩家,快速成为一个“...
aapoker透视!WePoK... 您好,WePoKer有没有透视软件挂这款游戏可以开挂的,确实是有挂的,需要了解加微【48527505...
红龙扑克开挂!微扑克的辅助工具... 很多人使用云端 AI 时,都担心微扑克的辅助工具有哪些、内部资料上传带来隐私风险。这款本地运行的 A...
aapoker辅助!wepok... 您好:wepoker私人局怎么设置抽水这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会...
aapoker辅助挂!wepo... aapoker辅助挂!wepoker透视挂安全吗,普及辅助挂多功能方法APP策略AI 智能体黑科技再...
红龙PoKer辅助挂!wepo... 您好:wepokerplus透视挂真的假的这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌...
德扑之星辅助挂!德州ai辅助有... 德扑之星辅助挂!德州ai辅助有用吗,详细辅助挂多功能下载APP指南书是一款可以让一直输的玩家,快速成...