当前位置:网站首页>[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
边栏推荐
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- [offer18] delete the node of the linked list
- 音乐播放(Toggle && PlayerPrefs)
- [Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
- There is no red exclamation mark after SVN update
- [offer29] sorted circular linked list
- FairyGUI循環列錶
- PRIDE-PPPAR源码解析
- idea中好用的快捷键
- [leetcode19]删除链表中倒数第n个结点
猜你喜欢
Naive Bayesian theory derivation
Unity3D制作注册登录界面,并实现场景跳转
NovAtel 板卡OEM617D配置步骤记录
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data
微信小程序开发心得
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Unity场景跳转及退出
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
FairyGUI簡單背包的制作
rtklib单点定位spp使用抗差估计遇到的问题及解决
随机推荐
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
[算法] 剑指offer2 golang 面试题10:和为k的子数组
Introduction to the daily practice column of the Blue Bridge Cup
Database course design: college educational administration management system (including code)
Itext 7 生成PDF总结
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
[leetcode622]设计循环队列
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
Game 280 weekly
How to reduce the shutdown time of InnoDB database?
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
最短Hamilton路径 (状压DP)
How to add music playback function to Arduino project
2021.11.10汇编考试
idea中好用的快捷键
FairyGUI增益BUFF数值改变的显示
Easy to use shortcut keys in idea
[offer78] merge multiple ordered linked lists
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
Combination of fairygui check box and progress bar