当前位置: 首页 > wzjs >正文

网站源码 带后台建设网站的模板

网站源码 带后台,建设网站的模板,网络营销推广渠道,上饶网站制作需要多少钱给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 1: 输入:…

 

给定一个含有 n 个正整数的数组和一个正整数 target 。

找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度如果不存在符合条件的子数组,返回 0 。

示例 1:

输入:target = 7, nums = [2,3,1,2,4,3]
输出:2
解释:子数组 [4,3] 是该条件下的长度最小的子数组。

示例 2:

输入:target = 4, nums = [1,4,4]
输出:1

示例 3:

输入:target = 11, nums = [1,1,1,1,1,1,1,1]
输出:0

n = 1 的时候直接返回 

n = 偶数的时候最后的一个元素的下标是results[i ] [j + 1]

n = 奇数的时候最后一个元素的下标是results[i + 1] [j + 1]

public int[][] generateMatrix(int n) {int [][] results = new int [n][n];int start = 1;int i = 0;int j = 0;int x = 0;int y = 0;int x1 = n - 1;int y1 = n - 1;if(n == 1){return new int [][]{{1}};}while(start <= n * n){for(j = y; j < y1 ; j++) {results[x][j] = start++;}for(i = x; i < x1 ; i++){results[i][y1] = start++;}for(j = y1; j > y; j--){results[x1][j] = start++;}for(i = x1; i > x; i--){results[i][y] = start++;}if(start == n * n){if(n % 2 == 0){results[i][j +  1] = start;}else {results[i + 1][j + 1] = start;}break;}x = x + 1;y = y + 1;x1 = x1  - 1;y1 = y1  - 1;}return results;}

给定一个含有 n 个正整数的数组和一个正整数 target 。

找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度如果不存在符合条件的子数组,返回 0 。

示例 1:

输入:target = 7, nums = [2,3,1,2,4,3]
输出:2
解释:子数组 [4,3] 是该条件下的长度最小的子数组。

示例 2:

输入:target = 4, nums = [1,4,4]
输出:1

示例 3:

输入:target = 11, nums = [1,1,1,1,1,1,1,1]
输出:0
   public int minSubArrayLen(int target, int[] nums) {int i = 0;int sum = 0;int len = Integer.MAX_VALUE;for(int j = 0; j < nums.length; j++){sum += nums[j];while(sum >= target){ // 过滤结果len = Math.min(len,j - i +  1);sum -= nums[i]; // 缩小窗口i++;}}return len == Integer.MAX_VALUE? 0: len;}

给定一个整数数组 Array,请计算该数组在每个指定区间内元素的总和。

输入描述

第一行输入为整数数组 Array 的长度 n,接下来 n 行,每行一个整数,表示数组的元素。随后的输入为需要计算总和的区间,直至文件结束。

输出描述

输出每个指定区间内元素的总和。

输入示例

5
1
2
3
4
5
0 1
1 3

1
2
3
4
5
6
7
8

输出示例

3
9

1
2

数据范围:

0 < n <= 100000

 

 

  public static void prefixTotal(){Scanner sc = new Scanner(System.in);int n = sc.nextInt();int [] nums = new int [n];for(int i = 0;i < n; i++){nums[i] = sc.nextInt();}int [] p = new int [n +  1];int sum = nums[0];p[0] = nums[0];for(int i = 1; i < n; i++){ //  1  2  3  4  5sum += nums[i - 1];p[i] = p[i - 1] + nums[i - 1];}while(sc.hasNext()){int left = sc.nextInt();int right = sc.nextInt();System.out.println(p[right + 1] - p[left]);}}


文章转载自:

http://7dj1ZnnH.wcqkp.cn
http://oGcIDt7X.wcqkp.cn
http://VKO9FLWV.wcqkp.cn
http://oXklfM2N.wcqkp.cn
http://Rvs1onBd.wcqkp.cn
http://PdN5D51I.wcqkp.cn
http://ELJvGtoB.wcqkp.cn
http://VLTXh1EV.wcqkp.cn
http://njGNYEUg.wcqkp.cn
http://NeiYdGXM.wcqkp.cn
http://M5uJljkQ.wcqkp.cn
http://L8Zojgcg.wcqkp.cn
http://TVtHsO9n.wcqkp.cn
http://faULmNoq.wcqkp.cn
http://buB6YKt6.wcqkp.cn
http://8HFxdKLF.wcqkp.cn
http://OdOyA8kU.wcqkp.cn
http://RxtW4PjR.wcqkp.cn
http://k0DfiIJ9.wcqkp.cn
http://V8Mehy98.wcqkp.cn
http://seQnTLHI.wcqkp.cn
http://T69hDKKw.wcqkp.cn
http://6pXdC9AJ.wcqkp.cn
http://oAuwRQXh.wcqkp.cn
http://cjNeGzMU.wcqkp.cn
http://QK62Uf9p.wcqkp.cn
http://zTUZlUUz.wcqkp.cn
http://ru7ZkWM7.wcqkp.cn
http://PXJ9CYa5.wcqkp.cn
http://lM1dyJtc.wcqkp.cn
http://www.dtcms.com/wzjs/644550.html

相关文章:

  • 网站开发视频 百度云wordpress可以注册了
  • 个人做网站接装修活哪个网站好成都小程序开发价格
  • 宁波专业网站定制制作服务在虚拟主机上建设多个网站
  • 做视频网站要什么格式网站开发怎么使用维语
  • 上海城乡建设网站证件查询建设网点查询附近
  • 如何做木工雕刻机网站曲阜住房城乡建设局网站
  • 青海媒体网站建设公司stm32做网站服务器
  • 营销型网站建设课程wordpress打赏工具
  • 电子商务网站建设体会那家专门做特卖的网站
  • 网站设计 现在流行的导航方式深圳做网站比较好的公司有哪些
  • 全网网站建设优化装潢公司网站模板
  • 完整网站开发教程网络营销服务管理
  • 电子商务网站建设与开发做网站的边框
  • 海洋网站建设网络水果电商运营方案
  • 福建省南平市建设局网站企业网站建设中在方案设计上
  • 婚礼网站模板三亚建设工程信息网站
  • 地方资讯网站源码爱企查企业服务平台
  • 做网站前台要学什么课程合肥网站建设模块
  • 福田做商城网站建设哪家便宜厦门网站制
  • 个人网站备案内容不合格装修公司品牌包装设计
  • 网站加后台桂林漓江介绍
  • 电子商务网站系统手绘元素素材
  • 佛山网站常见的问题建立网站的市场价格
  • 徐州住房与建设局网站wordpress 代码框
  • wordpress教育主题免费网站建设网站优化软件
  • 欧美风格网站源码电脑网址大全2345
  • 义乌网站建设九wordpress打赏链接怎么实现
  • 成都谁做捕鱼网站asp网站默认后台
  • 做物流有哪些网站博客网站开发流程
  • 关于酒店网站建设的摘要搜索引擎优化的作用是什么