当前位置:网站首页>Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
2022-07-02 05:33:00 【Envy the cloud rather than the king】
public class Continuous and not less than S The shortest subsequence of {
static int S = 15;
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = {5, 1, 3, 5, 10, 7, 4, 9, 2, 8};
int sum = 0;
int begin = 0;
int end =0;
int left = 0;
int right = -1;
int min = arr.length-1;
while(true) {
while(right<arr.length-1&&sum<S) {// Pay attention to the boundary problem , Here you can prevent the array from crossing the bounds
sum += arr[++right];// Move the right endpoint , until sum Greater than or equal to S
}
if(sum<S) break;//while Circulation outlet
end =right;
min = Min(min,end - begin +1);// Find a relatively small interval length that meets the conditions ,
sum -= arr[left++];// Through the outer layer while Cycle left endpoint
begin = left;
}
System.out.println(min);
}
public static int Min(int a,int b) {
if(a>b) {
return b;
}
else return a;
}
}
边栏推荐
- Ubuntu 20.04 installing mysql8
- Usage record of vector
- Fabric.js 圆形笔刷
- Database batch insert data
- Basic use of form
- Fabric. JS 3 APIs to set canvas width and height
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- "Original, excellent and vulgar" in operation and maintenance work
- Gee series: Unit 2 explore datasets
- RNN recurrent neural network
猜你喜欢
Fabric. JS activation input box
Gee series: unit 6 building various remote sensing indexes in Google Earth engine
6.网络-基础
Gee series: Unit 4 data import and export in Google Earth engine
With an amount of $50billion, amd completed the acquisition of Xilinx
Fabric.js 居中元素
Gee: create a new feature and set corresponding attributes
RNN recurrent neural network
Dark horse notes -- map set system
Gee: use of common mask functions in remote sensing image processing [updatemask]
随机推荐
线程池概述
Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js 背景不受视口变换影响
7.TCP的十一种状态集
Fabric.js 自由绘制矩形
Gee series: Unit 2 explore datasets
Fabric. JS iText superscript and subscript
Creation and destruction of function stack frames
Zzuli:1065 count the number of numeric characters
Installation du tutoriel MySQL 8.0.22 par centos8
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
Using QA band and bit mask in Google Earth engine
7.1 simulation summary
Record sentry's path of stepping on the pit
Win10 copy files, save files... All need administrator permission, solution
2022-2-15 learning xiangniuke project - Section 8 check login status
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)