当前位置:网站首页>Force deduction solution summary 713- subarray with product less than k
Force deduction solution summary 713- subarray with product less than k
2022-06-12 02:08:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link : Power button
describe :
Give you an array of integers nums And an integer k , Please return that the product of all elements in the subarray is strictly less than k The number of consecutive subarrays of .
Example 1:
Input :nums = [10,5,2,6], k = 100
Output :8
explain :8 The product is less than 100 The subarrays of are :[10]、[5]、[2],、[6]、[10,5]、[5,2]、[2,6]、[5,2,6].
It should be noted that [10,5,2] It's not that the product is less than 100 Subarray .
Example 2:
Input :nums = [1,2,3], k = 0
Output :0
Tips :
1 <= nums.length <= 3 * 104
1 <= nums[i] <= 1000
0 <= k <= 106
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/subarray-product-less-than-k
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * If this question is double every time for loop , It is very simple , however O(n2) Complexity , Will exceed the time limit . * My idea is that each cycle , From 0 Bit start , Multiplicative multiplication . If it is greater than k, If you continue to multiply, it must be greater than K, Reset the current result , And then from the 1 Bit start
Code :
public class Solution713 {
public int numSubarrayProductLessThanK(int[] nums, int k) {
int result = 0;
int currentValue = 1;
for (int i = 0; i < nums.length; i++) {
currentValue = 1;
for (int j = i; j < nums.length; j++) {
currentValue *= nums[j];
if (currentValue >= k) {
break;
}
result++;
}
}
return result;
}
}边栏推荐
- Add sequence number column to MySQL query result set
- 阿里云oss文件上传系统
- 力扣解法汇总965-单值二叉树
- 力扣解法汇总824-山羊拉丁文
- Why do we use Google search ads?
- 没有文笔,大家多多包涵
- 力扣解法汇总675-为高尔夫比赛砍树
- Summary of force deduction method 417- Pacific Atlantic current problems
- Linux(CentOS7)安装MySQL-5.7版本
- PHP development 09 article module deletion and article classification writing
猜你喜欢

竞价广告每次点击出价多少钱是固定的吗?

UE4\UE5触摸屏touch事件:单指、双指

Why do we use Google search ads?

Don't miss it! Five large data visualization screens that HR must collect

Operating mechanism of Google ads bidding

消防栓监测系统毕业设计---论文(附加最全面的从硬件电路设计->驱动程序设计->阿里云物联网搭建->安卓APP设计)

Summary of concrete (ground + wall) + Mountain crack data set (classification and target detection)

ACL 2022 | 预训练语言模型和图文模型的强强联合

自适应搜索广告有哪些优势?

How to automatically color cells in Excel
随机推荐
代理与反射(二)
serialization and deserialization
力扣解法汇总面试题 17.11-单词距离
微信公众号开发地理位置坐标的转换
Leetcode 45 jump game II
如何提高广告的广告评级,也就是质量得分?
Google Ads 的优势
Leetcode 55 jump game
Is there a female Bluetooth headset suitable for girls? 38 Bluetooth headsets worth getting started
Operating mechanism of Google ads bidding
Graphic data analysis | business cognition and data exploration
力扣解法汇总1728-猫和老鼠 II
Alicloud OSS file upload system
力扣解法汇总824-山羊拉丁文
PHP builds a high-performance API architecture based on sw-x framework (III)
ozzanimation-基於sse的動作系統
A mystery of the end of vagrant up
[adjustment] in 2022, the Key Laboratory of laser life sciences of the Ministry of education of South China Normal University enrolled adjustment students in optics, electronic information, biomedicin
Google 搜索广告系列设置前有哪些准备工作?
[adjustment] notice on the opening of the 2022 pre adjustment system for postgraduate enrollment of Shanghai Second University of Technology