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]

相关内容

热门资讯

透视透视(wpK)微扑克辅助挂... 透视透视(wpK)微扑克辅助挂(透视)详细辅助技巧教程(果然是真的有挂)进入游戏-大厅左侧-新手福利...
aapoker俱乐部!aapo... aapoker俱乐部!aapoker下载教程,(aa扑克)原来存在有挂(详细辅助大神讲解);1、aa...
透视安卓版(德州nzt)德州A... 透视安卓版(德州nzt)德州AI智能辅助机器人(透视)确实有挂(详细辅助教你教程)1、许多玩家不知道...
透视代打(微扑克)wpk德州透... 透视代打(微扑克)wpk德州透视辅助(透视)详细辅助教你攻略(其实真的是有挂);亲,关键说明,wpk...
透视透视挂(wepower德州... 透视透视挂(wepower德州)德州ai辅助软件(透视)确实真的是有挂(详细辅助技巧教程);一、德州...
aapoker辅助!aapok... aapoker辅助!aapoker怎么设置牌局,(AAPoker)都是有挂(详细辅助攻略教程);1、...
透视计算(WpK)wpk透视辅... 透视计算(WpK)wpk透视辅助(透视)详细辅助专业教程(好像真的是有挂)1、构建自己的wpk透视辅...
aapoker外挂!aapok... aapoker外挂!aapoker有挂吗,(aapokeR)竟然真的是有挂(详细辅助新2025教程)...
透视总结(线上wpk德州)德扑... 透视总结(线上wpk德州)德扑之星ai代打(透视)一直真的有挂(详细辅助玩家教程)1、德扑之星ai代...
透视透视(wpK)微扑克辅助挂... 透视透视(wpK)微扑克辅助挂(透视)详细辅助安装教程(好像是有挂)暗藏猫腻,小编详细说明微扑克辅助...