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.

题目地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/

题目意思:给出一个字符串,输出最长的子串的长度,子串不能有重复的字符。(子串是连续的。)

解题思路:   依次读取字符串的每一个字符,如果第一次出现则当前子串长度+1,否则:首先判断当前长度是否大于最大长度,是则替换最大长度。然后

      查找重复的字符是在原字符串哪里出现的。

代码如下:

 int lengthOfLongestSubstring(char* s) {
     ,currlen = ;
     ], i, j, start = ;
     memset(table, , sizeof(table));
     ; s[i] != '\0'; ++i){
          ){
             if (currlen > maxlen){
                 maxlen = currlen;
             }
             for(j = start; j < i; ++j){ //start记录重复的字符后一个位置
                 if (s[j] == s[i]){
                     table[s[j]] = ;
                     start = j+;
                     break;
                 }else{
                     --currlen;
                     table[s[j]] = ;
                 }
             }
         }else{
             ++currlen;
         }
     }
     if (currlen > maxlen){
         maxlen = currlen;
     }
     return maxlen;
 }

Longest Substring Without Repeating Characters(C语言实现)的更多相关文章

  1. leetcode: longest substring without repeating characters

    July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...

  2. leetcode 3 Longest Substring Without Repeating Characters最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  3. LeetCode——Problem3:Longest Substring Without Repeating Characters

    哎哟我天啊.这道题快折磨死我了.刚开始连题都没看明白,就是不知道substring是什么意思.研究了好长时间才看出来的. 光辉历史呀...菜死了 1.题目 Given a string, find t ...

  4. Leetcode 3. Longest Substring Without Repeating Characters(string 用法 水题)

    3. Longest Substring Without Repeating Characters Medium Given a string, find the length of the long ...

  5. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  6. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  7. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  8. 3. Longest Substring Without Repeating Characters(c++) 15ms

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  9. 【leetcode】Longest Substring Without Repeating Characters

    题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...

随机推荐

  1. Rxjava入门

    简介 RxJava是一个开源的Rx框架ReactiveX的java版本. ReactiveX的主要目的是通过一系列Observable组合异步或事件代码.其中使用的是观察者模式. 可以吧Reactiv ...

  2. 有关bootstrap

    最近在接触对移动浏览器很友好的bootstrap,遂整理了一点笔记: 简单的html页面: <!DOCTYPE html><html> <head> <tit ...

  3. Atitit事件代理机制原理 基于css class的事件代理

    Atitit事件代理机制原理 基于css class的事件代理 1.1. 在javasript中delegate这个词经常出现,看字面的意思,代理.委托1 1.2. 事件代理1 1.3. 代理标准化规 ...

  4. WCF 安全性 之 Windows

    案例下载 http://download.csdn.net/detail/woxpp/4113172 服务端配置代码 <system.serviceModel> <services& ...

  5. WCF学习之旅——第一个WCF示例(一)

    最近需要用到WCF,所以对WCF进行了解.在实践中学习新知识是最快的,接下来先做了一个简单的WCF服用应用示例. 本文的WCF服务应用功能很简单,却涵盖了一个完整WCF应用的基本结构.希望本文能对那些 ...

  6. Js的语法和循环

    1.蓝球弹起的高度 篮球从10米高的地方落下,每次弹起的高度是原来的0.3倍,问弹跳10次之后篮球的高度. <script type="text/javascript"> ...

  7. 创建第二个 local network - 每天5分钟玩转 OpenStack(84)

    GUI 中有两个地方可以创建 network: 1. Project -> Network -> Networks 这是普通用户在自己的 tenant 中创建 network 的地方. 2 ...

  8. Android随笔之——Android ADB详解

    ADB全称Android Debug Bridge, 是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的andriod设备.它主要有以下几个功能: 1.运 ...

  9. C# 将PDF文件转换为word格式

    Pdf(Portable Document Format)意为“便携式文档格式”,是现在最流行的文件格式之一,它有很多优点如:尺寸较小.阅读方便.操作系统平台通用等,非常适合在网络上传播和使用.如今在 ...

  10. Nodejs之MEAN栈开发(四)---- form验证及图片上传

    这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/stoneniqiu/R ...