2024/9/6 Hot100 substring 未完成
This commit is contained in:
parent
8ba279f371
commit
de9c5dfa67
|
@ -0,0 +1,49 @@
|
||||||
|
package com.cool.hot100.substring;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/09/06/13:57
|
||||||
|
* DayNumber 1
|
||||||
|
* Hard 3
|
||||||
|
* Level ?
|
||||||
|
*/
|
||||||
|
public class Num79 {
|
||||||
|
|
||||||
|
public String minWindow(String s, String t) {
|
||||||
|
if(s.length()<t.length()){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
int minLeft=Integer.MIN_VALUE;
|
||||||
|
int minRight=Integer.MAX_VALUE;
|
||||||
|
int left=0;
|
||||||
|
int right=0;
|
||||||
|
char[] charArray=s.toCharArray();
|
||||||
|
int index=0;
|
||||||
|
Map<Character,Integer> tMap=new HashMap<>();
|
||||||
|
Map<Character,Integer> sMap=new HashMap<>();
|
||||||
|
for(int i=0;i<t.length();i++){
|
||||||
|
tMap.put(t.charAt(i),tMap.getOrDefault(i,0)+1);
|
||||||
|
}
|
||||||
|
for(int i=0;i<charArray.length;i++){
|
||||||
|
if(tMap.containsKey(charArray[i])){
|
||||||
|
sMap.put(charArray[i],sMap.get(charArray[i])+1);
|
||||||
|
if(tMap.get(charArray[i])>sMap.get(charArray[i])){
|
||||||
|
right++;
|
||||||
|
}else{
|
||||||
|
while (sMap.get(charArray[left])>tMap.get(charArray[left])){
|
||||||
|
sMap.put(charArray[left],sMap.get(charArray[left])-1);
|
||||||
|
}
|
||||||
|
left++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
right++;
|
||||||
|
}
|
||||||
|
return s.substring(left,right);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue