1 

public class Solution {
public static int lengthOfLongestSubstring(String s) { char[] arr = s.toCharArray();
int pre = 0; HashMap<Character, Integer> map = new HashMap<Character, Integer>(); for (int i = 0; i < arr.length; i++) {
if (!map.containsKey(arr[i])) {
map.put(arr[i], i);
} else {
pre = pre > map.size() ? pre : map.size();
i = map.get(arr[i]);
map.clear();
}
} return Math.max(pre, map.size());
}
}
 public class Solution {
public String minWindow(String S, String T) {
char s[]=S.toCharArray();
if(S=="")return "";
int beg=0;
int end=0;
int d[]=new int[128];
int size=0;
for(int i=0;i<T.length();i++)
{
if(d[t[i]]==0) size++;
d[t[i]]++;
}
int d2[]=new int[128];
int s1=0;
boolean flag=false; while(end<s.length)
{
if(d[s[end]]==0) {end++;continue;}
d2[s[end]]++;
if(d2[s[end]]==d[s[end]]) s1++;
end++;
if(s1==size)
{
while(d2[s[beg]]>d[s[beg]]||d[s[beg]]==0) {d2[s[beg]]--;beg++;}
flag=true;
break;
} }
if(!flag) return "";
int aend=end-1;
int abeg=beg;
int amin=end-beg; while(end<s.length)
{
if(d[s[end]]==0){end++;continue;}
d2[s[end]]++; while((d2[s[beg]]>d[s[beg]])||d[s[beg]]==0) {
d2[s[beg]]--;beg++;
if(end-beg+1<amin)
{amin=end-beg+1;
aend=end;
abeg=beg; } }
end++; } //
return S.substring(abeg,aend+1); }
}

Minimum Window Substring &&& Longest Substring Without Repeating Characters 快慢指针,都不会退,用hashmap或者其他结构保证的更多相关文章

  1. [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string S, find the length of the longest substring T that contains at most two distinct char ...

  2. [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string s , find the length of the longest substring t  that contains at most 2 distinct char ...

  3. [LeetCode] Minimum Window Subsequence 最小窗口序列

    Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequence of ...

  4. [LeetCode] 727. Minimum Window Subsequence 最小窗口序列

    Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequence of ...

  5. [LeetCode] 3. Longest Substring Without Repeating Characters 解题思路

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

  6. [LeetCode] 3.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 with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  8. [LeetCode] Longest Substring Without Repeating Characters (LinkedHashSet的妙用)

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

  9. [Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

随机推荐

  1. Object-API-NSLog

    NSLog中的基础数据类型 输出格式: NSLog("") char: %c short int: %hi %hx %ho unsigned short int: %hu %hx ...

  2. Cassandra CqlRow fetch DateType / Int32Type

    phpcassa library里有个namespace : use phpcassa\Schema\DataType; 当使用cql query得到cqlrow, int32 & Date ...

  3. 深入了解absolute

    1.absolute与float的相同的特性表现  a.包裹性  b.破坏性:父元素没有设置高或宽,父元素的高或宽取决于这个元素的内容  c.不能同时存在 2.absolute独立使用,不与relat ...

  4. javascript 事件对象

    1.事件对象  用来记录一些事件发生时的相关信息的对象  A.只有当事件发生的时候才产生,只能在处理函数内部访问  B.处理函数运行结束后自动销毁2.如何获取事件对象  IE: window.even ...

  5. 读取xml文件(可执行文件根目录debug)

    xml文件格式如下 <?xml version="1.0" encoding="utf-8" ?> <root> <appKey& ...

  6. 如何判断一个Div是否在可视区域,判断div是否可见

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. node.js操作mongoDB数据库

    链接数据库: var mongo=require("mongodb"); var host="localhost"; var port=mongo.Connec ...

  8. (转载)DBGridEh导出Excel等格式文件

    DBGridEh导出Excel等格式文件 uses DBGridEhImpExp; {--------------------------------------------------------- ...

  9. 2016031601 - 刻录ubuntu的U盘启动盘

    使用UltraISO来刻录ubuntu15.1的系统安装盘. 需要U盘1个,ubuntu15.1系统镜像文件. 具体步骤如下: a.安装UltraISO软件,具体软件安装. b.安装完成后进行系统刻录 ...

  10. WF工作流与管理类应用系统工作流需求实现的一些误区

             如今实现各种应用系统大家都知道工作流是一个非常重要的环节,不同的业务系统的工作流需求是需要找相应的工作流产品去实现的,因为不同工作流产品的架构细节也许会成为某类需求实现的瓶颈. WF ...