当前位置:网站首页>[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
边栏推荐
- 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
- 基本Dos命令
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- 燕山大学校园网自动登录问题解决方案
- GPS高程拟合抗差中误差的求取代码实现
- There is no red exclamation mark after SVN update
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- In 2020, the average salary of IT industry exceeded 170000, ranking first
- Vulnhub target: hacknos_ PLAYER V1.1
- [Chongqing Guangdong education] Shandong University College Physics reference materials
猜你喜欢
Unity3d, Alibaba cloud server, platform configuration
Idea problem record
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
FairyGUI增益BUFF数值改变的显示
FairyGUI增益BUFF數值改變的顯示
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
SVN更新后不出现红色感叹号
Naive Bayesian theory derivation
Force buckle 1189 Maximum number of "balloons"
随机推荐
Fabrication d'un sac à dos simple fairygui
FairyGUI按钮动效的混用
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
Fairygui joystick
[algorithm] sword finger offer2 golang interview question 2: binary addition
GPS高程拟合抗差中误差的求取代码实现
[offer9] implement queues with two stacks
Conditional probability
Matlab读取GNSS 观测值o文件代码示例
Office prompts that your license is not genuine pop-up box solution
Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
Expected value (EV)
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
Prove the time complexity of heap sorting
第一人称视角的角色移动
堆排序【手写小根堆】
NRF24L01 troubleshooting
编辑距离(多源BFS)
Compile GDAL source code with nmake (win10, vs2022)