题目描述

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. JAVA集合--Iterator接口

        本文首发于cartoon的博客     转载请注明出处:https://cartoonyu.github.io/cartoon-blog     上一篇文章中我在集合元素的遍历中已经有涉及到I ...

  2. XVIII Open Cup named after E.V. Pankratiev Stage 5: Eastern Grand Prix

    contest link easy: EI medium-easy: BCDGK medium: L medium-hard: AFH A. Artifacts B. Brackets and Dot ...

  3. uname - 显示输出系统信息

    总览 uname [OPTION]... 描述 显示相应的系统信息. 没有指定选项时,同 -s. -a, --all 显示所有的信息 -m, --machine 显示机器(硬件)类型 -n, --no ...

  4. 单个机器部署redis集群模式(一键部署脚本)

    一.检查机器是否安装gcc.unzip.wget 二.部署模式 #模式1: 将所有主从节点以及sentinel节点部署在同一台机器上 #模式2: 将一个数据节点和一个sentinel节点部署在一台机器 ...

  5. IDEA使用的JDK版本1.9换成1.8后,在IDEA中需要改的配置

    今天上午上课spring5使用注解方式的时候,发现jdk9不兼容,果断换jdk8 步骤如下 一.查看Project中的jdk 1.检查Project SDK:中jdk 版本是否为1.8版本 2.检查P ...

  6. Java获取properties配置文件信息

    调用方法:String url = PropertiesUtil.getProperty("url"); public class PropertiesUtil { public ...

  7. QueryList采集页面链接及对应标题

    <?php header('content-type:text/html;charset=utf-8'); require 'vendor/autoload.php'; use QL\Query ...

  8. bzoj1070题解

    [解题思路] 考虑拆点,得到一个二分图:左边点<i,j>表示第i个技师按顺序第j辆修的车,右边点k表示第k个车主,连接左右的边表示第k个车主可能成为第i个技师的第j个客户. 因为是二分图, ...

  9. 欧拉函数+反演——2019hdu多校6588

    \[ 求\sum_{i=1}^{n}(\sqrt[3]i,i)\\ 首先转化一下这个式子,考虑对于i\in[j^3,(j+1)^3-1],\sqrt[3]i=j\\ 所以可以枚举所有j,然后对i\in ...

  10. luoguP3281 [SCOI2013]数数

    传送门 抄的llj的代码 还有点问题没弄懂,先码着 //Achen #include<algorithm> #include<iostream> #include<cst ...