LeetCode3. Longest Substring Without Repeating Characters
来源:互联网 发布:java面向对象的4大特征 编辑:程序博客网 时间:2024/04/29 16:14
用的hashmap
考虑情况不足,wrong了两次,尴尬
import sun.java2d.pipe.SolidTextRenderer;import java.util.Arrays;import java.util.HashMap;import java.util.Map;/** * Created by hms on 2016/12/25. */public class Solution { public int lengthOfLongestSubstring(String s) { int n = s.length(); int k = 0; int count = 0; int p = 0; HashMap<Character, Integer> integerMap = new HashMap<>(); for(int i = 0; i < n; ++i){ if(!integerMap.containsKey(s.charAt(i))){ integerMap.put(s.charAt(i), i); ++count; k = Math.max(k, count); }else{ int index = integerMap.get(s.charAt(i)); for(int j = p; j <= index; ++j) integerMap.remove(s.charAt(j)); p = index + 1; count = i - index; if(count == 4){ System.out.println(i); } k = Math.max(k, count); integerMap.put(s.charAt(i), i); } } k = Math.max(k, count); return k; }}
0 0
- LeetCode3:Longest Substring Without Repeating Characters
- [LeetCode3] Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters leetcode3
- LeetCode3 Longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- leetcode3 longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- Leetcode3 Longest Substring Without Repeating Characters
- leetcode3--Longest Substring Without Repeating Characters
- leetcode3. Longest Substring Without Repeating Characters
- LeetCode3:Longest Substring Without Repeating Characters
- Leetcode3:Longest Substring Without Repeating Characters
- [leetcode3] Longest Substring Without Repeating Characters
- Leetcode3 : Longest Substring Without Repeating Characters
- LeetCode3. Longest Substring Without Repeating Characters
- LeetCode3. Longest Substring Without Repeating Characters
- leetcode3. Longest Substring Without Repeating Characters
- LeetCode3. Longest Substring Without Repeating Characters
- redis基础操作
- MTK收购VIA IP后的CDMA开发
- JS获取项目路径详解
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之一 - 初识gtest
- mvc 封装框架之关于 .haccess 文件(一)
- LeetCode3. Longest Substring Without Repeating Characters
- JFinal Web开发学习(十一)编辑已发布文章
- C语言 贪吃蛇
- MFC操作EXCEL例子
- 计算机视觉的比较有用的项目project, visual object tracking & human action recognition.
- 【Unity】(代码分析)Unity创建并保存XML
- JAVA redis 常用函数
- Teleport Pro使用教程
- Socket及时通信