当前位置:网站首页>Leetcode:1498. Number of subsequences that meet the conditions [sort + bisection + power hash table]
Leetcode:1498. Number of subsequences that meet the conditions [sort + bisection + power hash table]
2022-07-27 20:36:00 【White speed Dragon King's review】

analysis
Subsequence should be maximum and minimum , In fact, it doesn't matter if you sort
Fixed the smallest , You can find the largest
Then the middle option is optional
So there is 2 The power of
And then in order to accelerate ,2 To hash and save
Don't count every time
ac code
class Solution:
def numSubseq(self, nums: List[int], target: int) -> int:
MOD = 10 ** 9 + 7
n = len(nums)
nums.sort()
# Hash computing power memory
f = [1] * (n + 1)
for i in range(1, n + 1):
f[i] = f[i - 1] * 2 % MOD
# Fix the smallest
ans = 0
for i in range(n):
minn = nums[i]
maxn = target - minn
if maxn < minn:
break
idx = bisect_right(nums, maxn) - 1
if idx >= i:
ans += f[idx - i]
ans %= MOD
return ans
summary
Hash memory power acceleration
边栏推荐
- Set -- data deconstruction
- Oracle +JDBC
- It is said that Intel will stop the nervana chip manufactured by TSMC at 16nm
- es6删除对象的属性_ES6删除对象中的某个元素「建议收藏」
- MySQL 日志错误日志
- Pyqt5 rapid development and practice 4.3 qlabel and 4.4 text box controls
- Datepicker date selector in viewui compatible solution in ie11 browser
- Pyqt5 rapid development and practice 4.7 qspinbox (counter) and 4.8 QSlider (slider)
- Assignment 1 - Hello World ! - Simple thread Creation
- set--数据解构
猜你喜欢

Use cpolar to build a business website (5)

Solve the problem of displaying the scroll bar when there is no data in the viewui table

图解LeetCode——592. 分数加减运算(难度:中等)
![[rctf2015]easysql-1 | SQL injection](/img/69/aa1fc60ecf9a0702d35d876e8c3dda.png)
[rctf2015]easysql-1 | SQL injection

《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24

If you want to switch to software testing, you should pass these three tests first, including a 3000 word super full test learning guide

Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables

To share the denoising methods and skills of redshift renderer, you must have a look

一个程序员的水平能差到什么程度?

A new UI testing method: visual perception test
随机推荐
Ten year test old bird talk about mobile terminal compatibility test
什么是多层感知机(什么是多层感知机)
A new UI testing method: visual perception test
To share the denoising methods and skills of redshift renderer, you must have a look
[RCTF2015]EasySQL-1|SQL注入
Linked list~~~
es6删除对象的属性_ES6删除对象中的某个元素「建议收藏」
为什么需要第三方支付?
Learn about the 12 necessary animation plug-ins of blender
MySQL learning record (III) multi table query, sub query, paging query, case statement, single line function
Oracle Xe installation and user operation
京东:获得商品详情原数据 API
In 2019, the global semiconductor market revenue was $418.3 billion, a year-on-year decrease of 11.9%
CONDA common commands
Apple Mobile Bluetooth networking
Koin simple to use
Redis Hash 结构命令
[map set]
Check the internship salary of Internet companies: with it, you can also enter the factory
【深度学习】视频分类技术整理