23-Longest Substring Without Repeating Characters
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.
本题:中等难度
思路:动态规划
其中vs[j-1]保存连续子串,num表示去掉重复字符(包含)之前的字符$$
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int n = s.size();
if(n<=1)return n;
vector<vector<char> > vm(n);
vector<int> vi(n);
vi[0]=1;
vm[0].push_back(s[0]);
for(int i=1;i<n;++i)
{
vector<char>::iterator it= find(vm[i-1].begin(),vm[i-1].end(),s[i]);
if(it!=vm[i-1].end())
{
vector<char> vtmp(it+1,vm[i-1].end());
vm[i]=vtmp;
vm[i].push_back(s[i]);
vi[i]=vm[i-1].end()-it;
}
else{
vi[i]=vi[i-1]+1;
vm[i]=vm[i-1];
vm[i].push_back(s[i]);
}
}
return *max_element(vi.begin(),vi.end());
}
};
23-Longest Substring Without Repeating Characters的更多相关文章
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Longest Substring Without Repeating Characters(C语言实现)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- [LeetCode_3] Longest Substring Without Repeating Characters
LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLon ...
- Longest Substring Without Repeating Characters (c#)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters(Difficulty: Medium)
题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...
随机推荐
- git为单独的仓库设置提交的用户名
在我们平时的学习中可能有这么一种需求,在公司进行开发的时候,一般会参与多个项目的开发,而项目提交代码时,一般请求情况下提供的用户都是同一个,而我们为了方便可能会使用全局进行git 用户名的配置.但是空 ...
- 前端大牛带你了解JavaScript 函数式编程
前言 函数式编程在前端已经成为了一个非常热门的话题.在最近几年里,我们看到非常多的应用程序代码库里大量使用着函数式编程思想. 本文将略去那些晦涩难懂的概念介绍,重点展示在 JavaScript 中到底 ...
- oracle物化视图创建及删除
--删除物化表的日志表 DROP MATERIALIZED VIEW LOG ON 表名; --为将要创建物化视图的表添加带主键的日志表 CREATE MATERIALIZED VIEW LOG ON ...
- PHP笔记2__变量/字符串/类型转换/常量/,,
<?php //可变变量 $a = "ok"; $$a = "fine"; $$$a = "er"; echo $ok; echo & ...
- 前端面试手写代码——模拟实现new运算符
目录 1 new 运算符简介 2 new 究竟干了什么事 3 模拟实现 new 运算符 4 补充 预备知识: 了解原型和原型链 了解this绑定 1 new 运算符简介 MDN文档:new 运算符创建 ...
- linux 的 逻辑卷管理
lvm 逻辑卷管理器 关于逻辑卷管理lvm的一些操作 新建磁盘 sdcfdisk /dev/sdc 创建分区,更改分区id 为8e,改变分区类型为 lvm linux 创建物理卷与pv相关 pvcre ...
- sqlldr 导入有中文乱码问题
1.导入成功后,查看导入数据有乱码 2.查看字符集为uft8 select * from v$nls_parameters where PARAMETER like '%NLS_CHARACTERSE ...
- 算法学习->求解三角形最小路径及其值
00 问题 00-1 描述 对给定高度为n的一个整数三角形,找出从顶部到底部的最小路径和.每个整数只能向下移动到与之相邻的整数. 找到一个一样的力扣题:120. 三角形最小路径和 - 力扣(LeetC ...
- The art of multipropcessor programming 读书笔记-3. 自旋锁与争用(2)
本系列是 The art of multipropcessor programming 的读书笔记,在原版图书的基础上,结合 OpenJDK 11 以上的版本的代码进行理解和实现.并根据个人的查资料以 ...
- 【Python+postman接口自动化测试】(7)Postman 的使用教程
Postman v6的使用 Postman: 简单方便的接口调试工具,便于分享和协作.具有接口调试,接口集管理,环境配置,参数化,断言,批量执行,录制接口,Mock Server, 接口文档,接口监控 ...