2015-07-13 leetcode:Longest Substring Without Repeating Characters
来源:互联网 发布:js获取当前时间字符串 编辑:程序博客网 时间:2024/06/08 05:36
整理自我之前的博客
原文地址
Longest substring without repeating characters
#include<stdio.h>#include<stdlib.h>#include<map>#include<vector>#include<string>#include<cstdio>#include<iostream>using namespace std;int main(){ string s; getline(cin,s); int buf[256]; memset(buf,-1,sizeof(buf)); int index=-1; //用来判断是否重复出现,以及最后一次重复出现的位置定为index int Max=0; for (int i=0;i<s.size();i++) { if(buf[s[i]]>index) //如果buf的s[i]大于index的值,就说明该值出现过,并且已经被更改过值 //把字符转化为ASCII码之后,赋值到buf数组中 { index=buf[s[i]]; //如果某个值是重复出现过,只需要记录其 } if(i-index > Max) //只要记录所出现的字符串的最大长度即可,保留Max的值 { Max=i-index; } buf[s[i]]=i; //如果某个字符新出现的话,应该是更新到最后一个出现的位数 //需要先判断再赋值,否则第一次出现的字符都更改了 } cout<<Max<<endl; system("pause"); return Max;}
阅读全文
0 0
- 2015-07-13 leetcode:Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- [BFS] POJ 3126
- 10月31日解题报告
- java对redis基本操作
- 读书笔记——《Java 8实战》系列之方法引用
- css盒模型的padding 和margin
- 2015-07-13 leetcode:Longest Substring Without Repeating Characters
- 基础数据结构_模板
- poj 1564 Sum It Up
- springmvc的简单介绍
- 存储系统的分类
- flask web开发-用户验证代码分析(五)
- Javascript中最常用的61个经典技巧
- Spring 学习笔记(6)—— 基于注解的配置
- 关于rose ha 服务器双机实施注意点