通过把未访问的结点放到unordered_map中来判断是否重复,代码如下: class Solution { public: int lengthOfLongestSubstring(string s) { if(s == "") ; unordered_map<char,int> hash; ; ; ;i < s.length();i ++) { if(hash.find(s[i]) != hash.end()) { i = hash[s[i]]; hash.cl…
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst…
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb"…
索引 思路1:分治策略 思路2:Brute Force - O(n^3) 思路3:动态规划? O(n^2)版,错解之一:420 ms O(n^2)版,错解之二:388 ms O(n)版,思路转变: 100 ms 细节上的优化(JavaScript限定) 问题描述:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 思路1:分治策略 感觉两下半写完了..没啥收获,就别出心载先写了个分治版本,结果…
分析 贪心思想.注意更新每次判断的最长不同子串的左区间的时候,它是必须单调增的(有时候会在这里翻车). 代码 关掉流同步能有效提高速度. static const auto io_sync_off = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return nullptr; }(); class Solution { public: int lengthOfLongestSubstring(string s)…
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longest-substring-without-repeating-characters/ Total Accepted: 149135 Difficulty: Medium Given a string, find the length of the longest substring without…
题目链接 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest…
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst…
题目描述 Given a string, find the length of the longest substring without repeating characters. Example 1 Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2 Input: "bbbbb" Output: 1 Expl…
题目描述 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest…