当前位置:网站首页>[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
边栏推荐
- NRF24L01 troubleshooting
- Idea problem record
- FairyGUI簡單背包的制作
- 抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
- Prove the time complexity of heap sorting
- It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
- Fabrication d'un sac à dos simple fairygui
- Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- What are the advantages of using SQL in Excel VBA
猜你喜欢
随机推荐
[offer29] sorted circular linked list
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
MySQL performance tuning - dirty page refresh
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
Mysql database index
Introduction to the daily practice column of the Blue Bridge Cup
[899] ordered queue
Itext 7 生成PDF总结
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
Programming homework: educational administration management system (C language)
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
基于rtklib源码进行片上移植的思路分享
Easy to use shortcut keys in idea
Lean product development - Lean Software Development & lean product development
[offer78]合并多个有序链表
Agile development helps me
GPS高程拟合抗差中误差的求取代码实现
服务未正常关闭导致端口被占用
On March 15, the official version of go 1.18 was released to learn about the latest features and usage