国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

3. Longest Substring Without Repeating Characters

2019-11-06 08:21:06
字體:
來源:轉載
供稿:網友
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the length of 1.Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.Subscribe to see which companies asked this question.

動態規劃的簡單應用,存儲第i-1位置的最長串d[i-1],然后到第i位置,比較有s[i]的最長串和d[i-1],取最大值

class Solution {public: int lengthOfLongestSubstring(string s) { int dp =0; for (int t = 0;t < s.size();t++) { int l = 0; vector<bool> visited(300, false); for (int i = t;i >= 0;i--) if (visited[s[i]]) break; else { l++;visited[s[i]] = true; } dp = dp > l ? dp : l; } return dp; }};
上一篇:位運算

下一篇:實戰編程-回文序列

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇平县| 吉水县| 齐齐哈尔市| 清镇市| 车致| 临泽县| 刚察县| 赫章县| 乐都县| 墨竹工卡县| 安溪县| 镇远县| 东安县| 麦盖提县| 綦江县| 修文县| 上虞市| 利津县| 高唐县| 四子王旗| 五台县| 邻水| 穆棱市| 托克逊县| 德庆县| 朔州市| 邢台市| 无棣县| 咸丰县| 灵台县| 武威市| 蒙阴县| 盐源县| 桓仁| 巴林右旗| 五常市| 大埔县| 墨竹工卡县| 西华县| 台山市| 玉林市|