Longest Substring Without Repeating Characters
来源:互联网 发布:淘宝优惠券佣金怎么算 编辑:程序博客网 时间:2024/06/06 21:05
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 asubstring, "pwke"
is a subsequence and not a substring.
class Solution {public: int lengthOfLongestSubstring(string s) {if (s.empty() || (0 == s.size())){return 0;} char T[256] = {0};char T1[256] = {0};int mxl = 0;int lastMxl = 0;for (int i = 0; i < s.size(); i++){ int index = s[i];if (T[index] > 0){ int pos = T[index];for (int j = 0; j < mxl; j++){int tmp = T[T1[j]] - pos;T[T1[j]] = (tmp <= 0) ? 0 : tmp;}for (int j = 0; j < mxl; j++){if ((pos + j) < 256){T1[j] = T1[pos + j];}else{T1[j] = '\0';}}if (mxl > lastMxl){lastMxl = mxl;} mxl = mxl - pos;}T1[mxl++] = s[i];T[index] = mxl;}return (mxl > lastMxl) ? mxl : lastMxl; }};
阅读全文
0 0
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Codeforces 758C Unfair Poll
- display属性-深度探索
- CL
- 关于CMD显示彩色文字
- c# 泛型总结
- Longest Substring Without Repeating Characters
- php 的小细节
- 揭开nginx神秘面纱[一.nginx的安装和服务的操作]
- linux 更改屏幕亮度
- C3
- hdu1281 棋盘游戏 二分图最大匹配 枚举
- 关于双重指针指向
- 实例详解Java中如何对方法进行调用
- 递归二叉树的序列打印