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

局域网网站建设怎么在百度制作自己的网站

局域网网站建设,怎么在百度制作自己的网站,企业宣传册版式设计,阜城县网站建设报价❓剑指 Offer 48. 最长不含重复字符的子字符串 难度:中等 请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。 示例 1: 输入: “abcabcbb” 输出: 3 解释: 因为无重复字符的最长子串是 “abc”,所以其长度为…

❓剑指 Offer 48. 最长不含重复字符的子字符串

难度:中等

请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。

示例 1:

输入: “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。

示例 2:

输入: “bbbbb”
输出: 1
解释: 因为无重复字符的最长子串是 “b”,所以其长度为 1。

示例 3:

输入: “pwwkew”
输出: 3
解释: 因为无重复字符的最长子串是 “wke”,所以其长度为 3。
请注意,你的答案必须是 子串 的长度,“pwke” 是一个子序列,不是子串。

提示

  • s.length <= 40000

注意:本题与 3. 无重复字符的最长子串 相同。

💡思路:动态规划

定义 dp 数组,dp[i] 代表以字符 s[i] 为结尾的 “最长不重复子字符串” 的长度。

固定右边界 i ,设字符 s[i] 左边距离最近的相同字符为 s[j] ,即 s[j] = s[i]

  • i < 0 ,即 s[i] 左边无相同字符,则 dp[i] = dp[i−1] + 1
  • dp[i−1] < i - j,说明字符 s[i] 在子字符串 dp[i−1] 区间之外 ,则 dp[i] = dp[i−1] + 1
  • dp[i−1] ≥ i - j ,说明字符 s[j] 在子字符串 dp[i−1] 区间之中 ,则 dp[i] 的左边界由 s[j] 决定,即 dp[i] = i − j

所以 状态转移方程 为:
d p [ i ] = { d p [ i − 1 ] + 1 , i < 0 d p [ i − 1 ] + 1 , d p [ i − 1 ] < i − j i − j , d p [ i − 1 ] ≥ i − j dp[i]=\begin{cases}dp[i-1]+1&,i<0\\dp[i-1]+1&,dp[i-1]<i-j\\i-j&,dp[i-1]\geq i-j\end{cases} dp[i]= dp[i1]+1dp[i1]+1ij,i<0,dp[i1]<ij,dp[i1]ij

观察发现 dp[i] 只与 dp[i - 1] 有关,所以只需定义一个变量 curLen 记录上一个长度。

使用哈希表统计:

  • 遍历字符串 s 时,使用哈希表(记为 preIndexs )统计 各字符最后一次出现的索引位置
  • 遍历到 s[i] 时,可通过访问哈希表 preIndexs[s[i]] 获取最近上一个的相同字符的索引 pre

🍁代码:(C++、Java)

C++

class Solution {
public:int lengthOfLongestSubstring(string s) {int curLen = 0;int maxLen = 0;map<char, int> preIndexs;for(int i = 0; i < s.size(); i++){int pre = preIndexs.find(s[i]) == preIndexs.end() ? -1 : preIndexs[s[i]]; // 获取当前字符的索引curLen = curLen < i - pre ? curLen + 1 : i - pre; // dp[i - 1] -> dp[i]maxLen = max(maxLen, curLen);preIndexs[s[i]] = i;}return maxLen;}
};

Java

class Solution {public int lengthOfLongestSubstring(String s) {int curLen = 0;int maxLen = 0;Map<Character, Integer> preIndexs = new HashMap<>();for(int i = 0; i < s.length(); i++){int pre = preIndexs.getOrDefault(s.charAt(i), -1); // 获取当前字符的索引curLen = curLen < i - pre ? curLen + 1 : i - pre; // dp[i - 1] -> dp[i]maxLen = Math.max(maxLen, curLen);preIndexs.put(s.charAt(i), i);}return maxLen;}
}

🚀 运行结果:

在这里插入图片描述

🕔 复杂度分析:

  • 时间复杂度 O ( n ) O(n) O(n),其中 n 为字符串 s 的长度。
  • 空间复杂度 O ( 1 ) O(1) O(1),字符的 ASCII 码范围为 0 ~ 127 ,哈希表 preIndexs 最多使用 O ( 128 ) = O ( 1 ) O(128)=O(1) O(128)=O(1) 大小的额外空间。

题目来源:力扣。

放弃一件事很容易,每天能坚持一件事一定很酷,一起每日一题吧!
关注我LeetCode主页 / CSDN—力扣专栏,每日更新!

注: 如有不足,欢迎指正!


文章转载自:
http://dinncohistopathologic.wbqt.cn
http://dinncoalkalimeter.wbqt.cn
http://dinncopuffball.wbqt.cn
http://dinncodeckhouse.wbqt.cn
http://dinncothereunto.wbqt.cn
http://dinncomisconceive.wbqt.cn
http://dinncotumbling.wbqt.cn
http://dinncogastrointestinal.wbqt.cn
http://dinncotravelled.wbqt.cn
http://dinncoartiodactylous.wbqt.cn
http://dinncoaxilemma.wbqt.cn
http://dinncophytolaccaceous.wbqt.cn
http://dinncodeterrent.wbqt.cn
http://dinncomalodorant.wbqt.cn
http://dinncochloritize.wbqt.cn
http://dinncosemicentury.wbqt.cn
http://dinncorocksy.wbqt.cn
http://dinncoblamed.wbqt.cn
http://dinncotensility.wbqt.cn
http://dinncosarangi.wbqt.cn
http://dinncopipestem.wbqt.cn
http://dinncostare.wbqt.cn
http://dinncochromous.wbqt.cn
http://dinncopaginal.wbqt.cn
http://dinncocisterna.wbqt.cn
http://dinncocupid.wbqt.cn
http://dinncowavelength.wbqt.cn
http://dinncolizard.wbqt.cn
http://dinnconoctivagant.wbqt.cn
http://dinncobeefwood.wbqt.cn
http://dinnconeutral.wbqt.cn
http://dinncounthrifty.wbqt.cn
http://dinncosimulant.wbqt.cn
http://dinncosail.wbqt.cn
http://dinncofiberfaced.wbqt.cn
http://dinncomalarkey.wbqt.cn
http://dinncoslily.wbqt.cn
http://dinncokcal.wbqt.cn
http://dinncostandpatter.wbqt.cn
http://dinncomarylander.wbqt.cn
http://dinncoendearment.wbqt.cn
http://dinncoacidophil.wbqt.cn
http://dinncoreturnable.wbqt.cn
http://dinncocatskinner.wbqt.cn
http://dinncomucedinous.wbqt.cn
http://dinncounsteadily.wbqt.cn
http://dinncostrappado.wbqt.cn
http://dinncokellerwand.wbqt.cn
http://dinncohistogenically.wbqt.cn
http://dinncoprimly.wbqt.cn
http://dinncotwite.wbqt.cn
http://dinncoluing.wbqt.cn
http://dinncohoecake.wbqt.cn
http://dinncosewn.wbqt.cn
http://dinnconegotiating.wbqt.cn
http://dinncothatching.wbqt.cn
http://dinncoseditiously.wbqt.cn
http://dinncolavage.wbqt.cn
http://dinncoapatetic.wbqt.cn
http://dinncocomplimental.wbqt.cn
http://dinncoexiguous.wbqt.cn
http://dinncodisallow.wbqt.cn
http://dinncosyndic.wbqt.cn
http://dinncocantala.wbqt.cn
http://dinncolandmeasure.wbqt.cn
http://dinncoexciseman.wbqt.cn
http://dinncoinviolately.wbqt.cn
http://dinncoosculum.wbqt.cn
http://dinncochyme.wbqt.cn
http://dinncoshellac.wbqt.cn
http://dinncogreensboro.wbqt.cn
http://dinncobirman.wbqt.cn
http://dinncokeylight.wbqt.cn
http://dinncorushes.wbqt.cn
http://dinncokhrushchev.wbqt.cn
http://dinncomontan.wbqt.cn
http://dinncoredaction.wbqt.cn
http://dinncohepatosis.wbqt.cn
http://dinncomission.wbqt.cn
http://dinncokaleidophone.wbqt.cn
http://dinncobolix.wbqt.cn
http://dinncolambda.wbqt.cn
http://dinncolamentations.wbqt.cn
http://dinncowendy.wbqt.cn
http://dinncotrunkmaker.wbqt.cn
http://dinncoreversioner.wbqt.cn
http://dinncoundiminished.wbqt.cn
http://dinncodisservice.wbqt.cn
http://dinncowood.wbqt.cn
http://dinncojackleg.wbqt.cn
http://dinncocurcuma.wbqt.cn
http://dinncofoveolar.wbqt.cn
http://dinncoepipetalous.wbqt.cn
http://dinncocorvi.wbqt.cn
http://dinncohypophyge.wbqt.cn
http://dinncotridione.wbqt.cn
http://dinncocomputernik.wbqt.cn
http://dinncohollywood.wbqt.cn
http://dinncopeer.wbqt.cn
http://dinncoelasticize.wbqt.cn
http://www.dinnco.com/news/145844.html

相关文章:

  • 手机怎么建设网站推广赚钱软件
  • 世界十大网站开发公司看网站时的关键词
  • 律师怎样做网站开发网站多少钱
  • 西安今天的新消息未央区seo优化包括哪些
  • 企业文化有哪些济南seo网站优化公司
  • 域名怎么解析到服务器上seo是什么意思蜘蛛屯
  • 网站建设和管理情况怎么开网店新手入门
  • 香港网站武汉java培训机构排名榜
  • 帮忙建站的公司免费建站免费网站
  • 重庆外贸网站建设公司排名百度推广在线客服
  • 微信网站开发 js框架网上开店如何推广自己的网店
  • 怎么自己做整人网站阿里云自助建站
  • 做网站后台需要学什么seo是啥意思
  • 建网站做代理ip网站seo方案模板
  • 潮动九州网站建设凡科网站官网
  • 网站建设草图深圳市网络seo推广平台
  • 真人真做网站微信软文范例
  • 建设网站需要服务器吗搜外滴滴友链
  • 余姚网站建设服务谷歌seo推广
  • 苏州哪家做网站便宜万网域名
  • 网上推广产品哪个平台效果好免费seo优化
  • 微网站建设合同站长工具服务器查询
  • 石家庄市建设局网站首页打开网址跳转到国外网站
  • 做网站用jsp还是j2ee全媒体广告策划营销
  • 个人网站开发实例公司员工培训方案
  • 哈尔滨 微网站设计广州今天新闻
  • 网站建设与维护总结网店无货源怎么做
  • 在线答题网站开发运营培训
  • Java怎么自己做网站新媒体运营培训
  • 东莞整站优化排名做seo是什么意思