Longest Substring Without Repeating Characters

3.Longest Substring Without Repeating Characters

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
Explanation: The answer is "b", with the length of 1.

Example 3:

Input: "pwwkew"
Output: 3
Explanation: 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.

Code

//
//  main.cpp
//  最长无重复子串
//
//  Created by mac on 2019/7/16.
//  Copyright © 2019 mac. All rights reserved.
//

#include 

#include 

#include 

#include 

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        string tmp="";
        vector Max = {0};
        for (int i=0; i

运行结果

8
0
Program ended with exit code: 0

参考文献

  • https://leetcode.com/problems/longest-substring-without-repeating-characters/

转载于:https://www.cnblogs.com/overlows/p/11196105.html

你可能感兴趣的:(Longest Substring Without Repeating Characters)