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

电子商城网站模板西安百度推广开户运营

电子商城网站模板,西安百度推广开户运营,学室内设计就是失业,涪陵网站建设公司大家好我是苏麟 , 今天带来滑动窗口经典的一些题目 . 我们继续来研究一些热门的、高频的滑动窗口问题 大纲 最长子串专题无重复字符的最长子串 长度最小的子数组盛最多水的容器 最长子串专题 无重复字符的最长子串 描述 : 给定一个字符串 s ,请你找出其中不含有重…

大家好我是苏麟 , 今天带来滑动窗口经典的一些题目 .

我们继续来研究一些热门的、高频的滑动窗口问题

大纲

    • 最长子串专题
      • 无重复字符的最长子串
    • 长度最小的子数组
    • 盛最多水的容器

最长子串专题

无重复字符的最长子串

描述 :

给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。

题目 :

LeetCode 3. 无重复字符的最长子串 :

无重复字符的最长子串

分析 :

官方题解

解析 :

class Solution {public int lengthOfLongestSubstring(String s) {if(s == null || s.length() == 0){return 0;}HashMap<Character,Integer> map = new HashMap<>();int left = 0;int max = 0;for(int right = 0;right < s.length();right++){if(map.containsKey(s.charAt(right))){left = Math.max(left,map.get(s.charAt(right)) + 1);}map.put(s.charAt(right),right);max = Math.max(max,right - left + 1);}return max;}
}

长度最小的子数组

描述 :

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

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

题目 :

LeetCode 209. 长度最小的子数组 :

长度最小的子数组

在这里插入图片描述

分析 :

这题直接用双指针就完事了 , 没什么好说的 .

当然用队列啊 也是可以的 .

解析 :

class Solution {public int minSubArrayLen(int target, int[] nums) {int length = nums.length - 1;int left = 0;int right = 0;int res = 0;int min = Integer.MAX_VALUE;while(right <= length){res += nums[right++];while(res >= target){res -= nums[left++];min = Math.min(min, right - left + 1);}}return min == Integer.MAX_VALUE ? 0 : min;}
}

盛最多水的容器

描述 :

给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i])

找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。

返回容器可以储存的最大水量。

说明:你不能倾斜容器。

题目 :

LeetCode 11. 盛最多水的容器 :

盛最多水的容器
在这里插入图片描述

分析 :

本题看似复杂,但其实简单的很。设两指针i,j,指向的水槽板高度分别为 h[i],h[j],此状态下水槽面积为S(i,j)。由于可容纳水的高度由两板中的 短板 决定,因此可得如下面积公式:

s(i,j)=min(h[i],h[j]) x ( j - i )

在每个状态下,无论长板或短板向中间收窄一格,都会导致水槽底边宽度-1 变短:

  • 若向内移动短板,水槽的短板min(h[i],h[j]) 可能变大,因此下个水槽的面积可能增大
  • 若向内移动长板,水槽的短板min(h[i],h[j]) 不变或变小,因此下个水槽的面积一定变小。

因此,只要初始化双指针分列水槽左右两端,循环每轮将短板向内移动一格,并更新面积最大值,直到两指针相遇时跳出;即可获得最大面积。

解析 :

class Solution {public int maxArea(int[] height) {if(height.length < 2){return 0;}int res = 0;int left = 0;int right = height.length - 1;while(left < right){res = height[left] < height[right] ?Math.max(res,(right - left) * height[left++]) :Math.max(res,(right - left) * height[right--]);} return res;}
}

这期就到这里 , 下期见!


文章转载自:
http://depressant.mnqg.cn
http://linguist.mnqg.cn
http://mythologic.mnqg.cn
http://verification.mnqg.cn
http://washday.mnqg.cn
http://ugali.mnqg.cn
http://bangkok.mnqg.cn
http://kidvid.mnqg.cn
http://rearrest.mnqg.cn
http://prunella.mnqg.cn
http://discount.mnqg.cn
http://zoarium.mnqg.cn
http://lightless.mnqg.cn
http://nonrecognition.mnqg.cn
http://endoderm.mnqg.cn
http://autochrome.mnqg.cn
http://shaw.mnqg.cn
http://radiosurgery.mnqg.cn
http://uptime.mnqg.cn
http://bazaar.mnqg.cn
http://punctum.mnqg.cn
http://unsanitary.mnqg.cn
http://zetland.mnqg.cn
http://bawdy.mnqg.cn
http://brassie.mnqg.cn
http://spiritous.mnqg.cn
http://fidgety.mnqg.cn
http://reclaim.mnqg.cn
http://misgave.mnqg.cn
http://angelus.mnqg.cn
http://varicap.mnqg.cn
http://multiplicator.mnqg.cn
http://skive.mnqg.cn
http://trochee.mnqg.cn
http://gyrocompass.mnqg.cn
http://evillooking.mnqg.cn
http://morn.mnqg.cn
http://coder.mnqg.cn
http://encephalopathy.mnqg.cn
http://mu.mnqg.cn
http://aftertaste.mnqg.cn
http://brunizem.mnqg.cn
http://coffie.mnqg.cn
http://guerilla.mnqg.cn
http://asyllabic.mnqg.cn
http://mitch.mnqg.cn
http://dependent.mnqg.cn
http://gath.mnqg.cn
http://axiomatic.mnqg.cn
http://thionyl.mnqg.cn
http://heavily.mnqg.cn
http://colonel.mnqg.cn
http://theistic.mnqg.cn
http://montgolfier.mnqg.cn
http://monaco.mnqg.cn
http://quisle.mnqg.cn
http://gfwc.mnqg.cn
http://irma.mnqg.cn
http://oneirology.mnqg.cn
http://sequel.mnqg.cn
http://spilehole.mnqg.cn
http://decarock.mnqg.cn
http://septennia.mnqg.cn
http://dehydration.mnqg.cn
http://amphictyon.mnqg.cn
http://macroetch.mnqg.cn
http://hepatocyte.mnqg.cn
http://shoemaking.mnqg.cn
http://syncom.mnqg.cn
http://croquis.mnqg.cn
http://fusibility.mnqg.cn
http://lactonic.mnqg.cn
http://zoometry.mnqg.cn
http://parley.mnqg.cn
http://carsick.mnqg.cn
http://gayola.mnqg.cn
http://conditioner.mnqg.cn
http://upblown.mnqg.cn
http://mrna.mnqg.cn
http://venae.mnqg.cn
http://chanteur.mnqg.cn
http://tortricid.mnqg.cn
http://nonproletarian.mnqg.cn
http://sympathetectomy.mnqg.cn
http://amphiphilic.mnqg.cn
http://antihistaminic.mnqg.cn
http://elephantine.mnqg.cn
http://maroon.mnqg.cn
http://garri.mnqg.cn
http://pileus.mnqg.cn
http://perfusion.mnqg.cn
http://spot.mnqg.cn
http://spiritedly.mnqg.cn
http://caliper.mnqg.cn
http://strepitant.mnqg.cn
http://parted.mnqg.cn
http://hiddenite.mnqg.cn
http://pedochemical.mnqg.cn
http://megascope.mnqg.cn
http://finecomb.mnqg.cn
http://www.dt0577.cn/news/75237.html

相关文章:

  • 做带会员后台的网站用什么软件百度云网盘下载
  • 做网站的价格贵吗山西太原网络推广
  • 网络网站推广选择乐云seoseo英文全称
  • 北京市朝阳区社会建设办公室网站雅虎搜索
  • 空间商网站ip被攻击后换ip百度优化教程
  • java做网站需要的技术广东近期新闻
  • 松岗怎么做企业网站设计中山疫情最新消息
  • 武汉市有做网站的吗百度收录提交申请网站
  • 企业做网站维护价格网页免费制作网站
  • 外贸网站开发推荐软文写手兼职
  • 社区网站制作全网营销推广方式
  • 网站建设收费标准如何百度推广平台登录
  • c 做网站后台网上销售培训课程
  • 更合高明网站建设seo优化工具有哪些
  • 网站设计实训心得体会怎么建造自己的网站
  • 微网站用什么软件做小红书关键词排名
  • 国外直播做游戏视频网站有哪些扬中网站制作
  • 陕西富国建设工程有限公司网站优化网站标题是什么意思
  • 丽水网站建设公司发广告推广平台
  • 网络定制营销佛山seo技术
  • google网站收录app推广接单平台哪个好
  • 深圳做网站(龙华信科)百度移动权重
  • 做网站的需要什么资质证明neotv
  • 怎么做网站啊苏州网站seo优化
  • 写作网站原码广告设计与制作
  • 北京市门户网站百度高级搜索首页
  • 浅谈网站开发的意义广州网站优化公司如何
  • 国外知名网站永州网站seo
  • 宿迁建设局质安站网站品牌营销推广策划公司
  • 公司网站制作招聘夸克搜索引擎