题意很简单,就是寻找一个字符串中连续的最长包含不同字母的子串. 其实用最朴素的方法,从当前字符开始寻找,找到以当前字符开头的最长子串.这个方法猛一看是个n方的算法,但是要注意到由于字符数目的限制,其实这是个O(Cn)的算法,最长也不过是C长度.所以我觉得普通方法应该是能过的. 于是写了一个,字符数目最大也不超过256所以代码如下: class Solution { public: int lengthOfLongestSubstring(string s) { ; ;i<s.length();i…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ 003. Longest Substring Without Repeating Characters[M] Longest Substring Without Repeating CharactersM 题目 思路 代码 题目 Given a string, fin…
LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLongestSubstring(string s) { int ans = 0, i = 0, j = 0; map <char , char> m; int n = s.size(); while (i < n && j < n){ // 左闭右开 if(m.find(s…
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. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest s…
题目如下: 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 E…
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 subst…
题目 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…
题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: 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 &q…