当前位置:网站首页>[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
边栏推荐
- Idea problem record
- What is the maximum length of MySQL varchar field
- Guided package method in idea
- 1041 be unique (20 points (s)) (hash: find the first number that occurs once)
- idea问题记录
- NovAtel 板卡OEM617D配置步骤记录
- Halcon knowledge: gray_ Tophat transform and bottom cap transform
- C programming exercise
- 3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
- FairyGUI循環列錶
猜你喜欢

3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法

Fairygui joystick
![[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和](/img/d5/4bda133498f71ae9fd7a64c6cba8f0.png)
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和

Combination of fairygui check box and progress bar

Teach you to release a DeNO module hand in hand

FairyGUI增益BUFF數值改變的顯示
![[算法] 剑指offer2 golang 面试题4:只出现一次的数字](/img/f7/23ffc81ec8e9161c15d863c1a67916.png)
[算法] 剑指offer2 golang 面试题4:只出现一次的数字

(core focus of software engineering review) Chapter V detailed design exercises
![[算法] 剑指offer2 golang 面试题1:整数除法](/img/e6/f17135207b3540ec58e5a9eed54220.png)
[算法] 剑指offer2 golang 面试题1:整数除法

NRF24L01 troubleshooting
随机推荐
Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
Teach you to release a DeNO module hand in hand
KF UD分解之伪代码实现进阶篇【2】
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
基于rtklib源码进行片上移植的思路分享
There is no red exclamation mark after SVN update
NRF24L01 troubleshooting
[leetcode622]设计循环队列
Halcon knowledge: gray_ Tophat transform and bottom cap transform
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
第一人称视角的角色移动
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Database table splitting strategy
RTKLIB: demo5 b34f.1 vs b33
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
微信小程序开发心得
FairyGUI摇杆
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
(core focus of software engineering review) Chapter V detailed design exercises