当前位置:网站首页>[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
2022-07-06 12:51:00 【Deng Jiawen jarvan】
[ Algorithm ] The finger of the sword offer2 golang Interview questions 9: The product is less than k Subarray
subject 1:

Ideas 1: The sliding window
Code
func numSubarrayProductLessThanK(nums []int, k int) int {
//start: 10:28,... end 11.23
// Ideas 1: The sliding window
// Processing parameters
if len(nums) == 0 || k <= 0 {
return 0
}
// The sliding window
res := 0
left,right,product := 0,0,1
for ;right < len(nums);right++ {
product *= nums[right]
for left <= right && product >= k {
product /= nums[left]
left ++
}
if left <= right {
res += right-left +1
}
}
return res
}
test
边栏推荐
- What is the maximum length of MySQL varchar field
- RTKLIB: demo5 b34f.1 vs b33
- [算法] 剑指offer2 golang 面试题1:整数除法
- (1) Introduction Guide to R language - the first step of data analysis
- Knowledge system of digital IT practitioners | software development methods -- agile
- 1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
- Lean product development - Lean Software Development & lean product development
- Database table splitting strategy
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- 抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
猜你喜欢

The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
![[算法] 劍指offer2 golang 面試題2:二進制加法](/img/c2/6f6c3bd4d70252ba73addad6a3a9c1.png)
[算法] 劍指offer2 golang 面試題2:二進制加法
![[Chongqing Guangdong education] Shandong University College Physics reference materials](/img/56/4ac44729c3e480a4f779d6a890363a.jpg)
[Chongqing Guangdong education] Shandong University College Physics reference materials

Guided package method in idea

RTKLIB: demo5 b34f.1 vs b33

Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)

FairyGUI摇杆

Mysql database index
![[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积](/img/e0/cea31070d6365eb57013cdead4a175.png)
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积

Teach you to release a DeNO module hand in hand
随机推荐
Game 280 weekly
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
[leetcode622] design circular queue
FairyGUI摇杆
服务未正常关闭导致端口被占用
FairyGUI循環列錶
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
Meanings and differences of PV, UV, IP, VV, CV
rtklib单点定位spp使用抗差估计遇到的问题及解决
GPS高程拟合抗差中误差的求取代码实现
Matlab读取GNSS 观测值o文件代码示例
Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
Minio file download problem - inputstream:closed
微信小程序开发心得
[算法] 剑指offer2 golang 面试题10:和为k的子数组
Containers and Devops: container based Devops delivery pipeline
FairyGUI增益BUFF数值改变的显示
基本Dos命令
2022国赛Re1 baby_tree