当前位置:网站首页>[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 are the functions and features of helm or terrain
- 编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
- The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
- [899]有序队列
- SVN更新后不出现红色感叹号
- On March 15, the official version of go 1.18 was released to learn about the latest features and usage
- [算法] 剑指offer2 golang 面试题10:和为k的子数组
- Lean product development - Lean Software Development & lean product development
- InnoDB dirty page refresh mechanism checkpoint in MySQL
- Knowledge system of digital IT practitioners | software development methods -- agile
猜你喜欢
随机推荐
Fairygui joystick
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
闇の連鎖(LCA+树上差分)
[Offer29] 排序的循环链表
Get the position of the nth occurrence of the string
[899] ordered queue
Unity3D,阿里云服务器,平台配置
FairyGUI条子家族(滚动条,滑动条,进度条)
[leetcode622]设计循环队列
2021.11.10 compilation examination
Liste des boucles de l'interface graphique de défaillance
Derivation of logistic regression theory
idea中好用的快捷键
KF UD分解之伪代码实现进阶篇【2】
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
Unity3D制作注册登录界面,并实现场景跳转
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
Servlet
Unity场景跳转及退出









