题目描述

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. 集合 HashMap 的原理,与 Hashtable、ConcurrentHashMap 的区别

    一.HashMap 的原理 1.HashMap简介 简单来讲,HashMap底层是由数组+链表的形式实现,数组是HashMap的主体,链表则是主要为了解决哈希冲突而存在的,如果定位到的数组位置不含链表 ...

  2. 2018 最新 spring boot 整合 swagger2 (swagger2 版本 2.8.0)

    好久没上了, 看到又有人回复了. 我就来修改一下. 修改时间  2018年5月16日 这回给你上全新版本. 至发稿时间,所有的包都是新版. 注意: 高版本需要添加  jaxb-api 包, 否则会报错 ...

  3. springboot + zipkin(brave-okhttp实现)

    一.前提 1.zipkin基本知识:附8 zipkin 2.启动zipkin server: 2.1.在官网下载服务jar,http://zipkin.io/pages/quickstart.html ...

  4. .Net中Task使用来提高代码执行效率

    技术不断更新迭代,更高效的执行效率越来越被重视,所以对Task的使用进行了简单使用做了整理与大家分享. .Net 中有了Task后使多线程编程更简单使用和操作,下面粘上代码进行简单说明: /// &l ...

  5. redis集群报错:(error) MOVED 5798 127.0.0.1:7001

    原因 这种情况一般是因为启动redis-cli时没有设置集群模式所导致. 解决方案 启动时使用-c参数来启动集群模式,命令如下: redis-cli -c -p 7000 测试 127.0.0.1:7 ...

  6. Unity 调用android

    { https://www.bilibili.com/video/av49002527 }

  7. DOM——创建元素的三种方式

    document.write()  document.write('新设置的内容<p>标签也可以生成</p>'); innerHTML  var box = document. ...

  8. Springboot 上传文件

    @PostMapping("/upload")//springboot可以直接扫描resource下的static文件夹下的静态文件 public String upload(@R ...

  9. 43 编译原理及cmake使用手册学习

    0 引言 大量开源库需要通过cmake编译后使用,了解cmake的基本指令以及CMakeLists.txt的写法非常重要,其基础是了解编译原理.另外,为了对cmake编译的代码进行调试,需要了解CMa ...

  10. 基于Netty的RPC架构学习笔记(四):netty线程模型源码分析(一)

    文章目录 如何提高NIO的工作效率 举个