当前位置:网站首页>[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
边栏推荐
- Database course design: college educational administration management system (including code)
- Devops' future: six trends in 2022 and beyond
- [算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
- [算法] 剑指offer2 golang 面试题4:只出现一次的数字
- [算法] 剑指offer2 golang 面试题1:整数除法
- FairyGUI条子家族(滚动条,滑动条,进度条)
- What are the functions and features of helm or terrain
- (the first set of course design) 1-4 message passing interface (100 points) (simulation: thread)
- 【RTKLIB 2.4.3 b34 】版本更新简介一
- 2021.11.10汇编考试
猜你喜欢

The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25

堆排序【手写小根堆】

(5) Introduction to R language bioinformatics -- ORF and sequence analysis

Teach you to release a DeNO module hand in hand

Unity scene jump and exit

Design and implementation of general interface open platform - (39) simple and crude implementation of API services

Office prompts that your license is not genuine pop-up box solution

(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart

Mysql database index

Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
随机推荐
Lean product development - Lean Software Development & lean product development
How to improve the deletion speed of sequential class containers?
[algorithm] sword finger offer2 golang interview question 2: binary addition
FairyGUI条子家族(滚动条,滑动条,进度条)
Unity3D,阿里云服务器,平台配置
C programming exercise
【GNSS】抗差估计(稳健估计)原理及程序实现
Unity3d, Alibaba cloud server, platform configuration
基于rtklib源码进行片上移植的思路分享
NovAtel 板卡OEM617D配置步骤记录
FairyGUI摇杆
What are the functions and features of helm or terrain
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
[offer29] sorted circular linked list
[算法] 劍指offer2 golang 面試題2:二進制加法
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
Prove the time complexity of heap sorting
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
In 2020, the average salary of IT industry exceeded 170000, ranking first
(the first set of course design) 1-4 message passing interface (100 points) (simulation: thread)