当前位置:网站首页>[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
边栏推荐
猜你喜欢
闇の連鎖(LCA+树上差分)
MySQL shutdown is slow
Idea problem record
FairyGUI簡單背包的制作
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Combination of fairygui check box and progress bar
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
Unity场景跳转及退出
堆排序【手写小根堆】
Office prompts that your license is not genuine pop-up box solution
随机推荐
GNSS定位精度指标计算
Unity3d makes the registration login interface and realizes the scene jump
NRF24L01 troubleshooting
雇佣收银员【差分约束】
Guided package method in idea
Containers and Devops: container based Devops delivery pipeline
Special palindromes of daily practice of Blue Bridge Cup
Fairygui loop list
[offer29] sorted circular linked list
Fairygui character status Popup
【RTKLIB 2.4.3 b34 】版本更新简介一
Programming homework: educational administration management system (C language)
Office提示您的许可证不是正版弹框解决
[offer78]合并多个有序链表
isEmpty 和 isBlank 的用法区别
FairyGUI按钮动效的混用
FairyGUI人物状态弹窗
[算法] 剑指offer2 golang 面试题2:二进制加法
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
[leetcode19] delete the penultimate node in the linked list