题目描述

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.

My solution(94ms,39.2MB)

class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<String,Integer> map = new HashMap<String,Integer>();
int result=0,current=1;
for(int i=0;i<s.length();){
String temp = s.substring(i,i+1);
if (!map.containsKey(temp)) {
map.put(temp,1);
i++;
}else{
i = current;
current++;
int len = map.size();
if(len > result){ result = len;}
map.clear();
}
if(map.size()>result){
result = map.size();
} }
return result;
}
}

LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)的更多相关文章

  1. leetcode第三题--Longest Substring Without Repeating Characters

    Problem:Given a string, find the length of the longest substring without repeating characters. For e ...

  2. leetcode第三题Longest Substring Without Repeating Characters java

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  3. LeetCode 第 3 题(Longest Substring Without Repeating Characters)

    LeetCode 第 3 题(Longest Substring Without Repeating Characters) Given a string, find the length of th ...

  4. 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)

    Given a string, find the length of the longest substring without repeating characters. Example 1:    ...

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

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

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

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  7. [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现

    最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...

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

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

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

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

随机推荐

  1. scala 基础笔记

    view bound:必须传入一个隐式转换函数 class [T <% Ordered [T]] content bound:必须传入一个隐式值 class [T : Ordering] !异步 ...

  2. win查看所有wifi密码

    for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh wlan show profiles') do @echo %j | finds ...

  3. Web开发常规调试方法与常见问题分析

    一.Web项目基本原理 现在的web项目大都已经前后端独立开发与部署. 前后端独立开发,一般是前端与后端通过web接口(常见的有RESTful与websocket)文档进行交流.前端开发人员先更具业务 ...

  4. 搭建一个node.js项目

    初始化项目 新建一个文件夹,运行 npm init 初始化项目 mkdir okadaGo cd okadaGo npm init 按照提示输入一些项目的相关信息 D:\web\node>mkd ...

  5. Django添加生产环境配置

    在初始化阶段,Django会帮我们创建一个settings.py目录,所有Django的配置都在这个模块中,这样就会产生一些问题,比如同一份配置怎么来更好的区分开发环境和线上环境.当然可以在setti ...

  6. java zxing 生成条形码和二维吗

    依赖 <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</art ...

  7. prufer序列的性质及相关结论

  8. 单源最短路径问题1 (Bellman-Ford算法)

    /*单源最短路径问题1 (Bellman-Ford算法)样例: 5 7 0 1 3 0 3 7 1 2 4 1 3 2 2 3 5 2 4 6 3 4 4 输出: [0, 3, 7, 5, 9] */ ...

  9. 【NOI2019模拟2019.7.4】朝夕相处 (动态规划+BM)

    Description: 题解: 这种东西肯定是burnside引理: \(\sum置换后不动点数 \over |置换数|\) 一般来说,是枚举置换\(i\),则\(对所有x,满足a[x+i]=a[i ...

  10. clipboard.js实现页面内容复制到剪贴板

    clipboard.js实现复制内容到剪切板,它不依靠flash以及其他框架,应用起来比较简单 <input type="text" name="copy_txt& ...