Update A30.java

This commit is contained in:
Mrhongxing committed 2026-10-19 00:36:03 +08:00
1 parent 6a0ea68a2f
commit 872aee5d20
1 file changed
+26 -45
+26 -45
View File
@@ -15,59 +15,40 @@ public class A30 {
* }
*/
public List<Integer> findSubstring(String s, String[] words) {
/*
* int time=0;
* ArrayList<String> temp = new ArrayList<>();
* aaa(time,words,temp);
*
* List<Integer> result = new ArrayList<>();
* for(String x:words){
* temp.setLength(0);
* }
*/
char[] a = s.toCharArray();
HashMap<String, Integer> temp = new HashMap<>();
List<Integer> result = new ArrayList<>();
HashSet<String> temp1 = new HashSet<>();
int left=0;
int right=1;
int w=words[0].length();
char[] chars=s.toCharArray();
HashMap<String,Integer> a=new HashMap<>();
HashMap<String,Integer> temp=new HashMap<>();
for(String x:words){
a.put(x, a.getOrDefault(x, 0)+1);
temp.put(x, 0);
}
int left=0;
int right=words[0].toCharArray().length+left;
StringBuilder sb = new StringBuilder();
int time=0;
int time1=0;
while (right<a.length) {
for(String x:words){
if(s.substring(left,right).equals(sb.toString()+x)&&!temp1.contains(x)){
sb.append(x);
temp1.add(x);
time++;
}else if(s.subSequence(right-words[0].toCharArray().length, right).equals(x)&&temp1.contains(x)){
sb.setLength(0);
temp1.clear();
sb.append(x);
temp1.add(x);
time=1;
left=right-words[0].toCharArray().length;
int count=a.size();
while(right+w<=s.length()){
String sub = s.substring(right, right+w);
if(temp.containsKey(sub)){
temp.put(sub, temp.get(sub)+1);
if(temp.get(sub)>a.get(sub)){
while(temp.get(sub)>a.get(sub)){
String sub1 = s.substring(left, left+w);
if(temp.containsKey(sub1)){
temp.put(sub1, temp.get(sub1)-1);
if(temp.get(sub1)==a.get(sub1)){
}
}
if(time==words.length){
temp1.remove(s.substring(left,left+words[0].toCharArray().length));
result.add(left);
time--;
left+=3;
sb.delete(0,words[0].toCharArray().length);
left+=w;
}
}else if(temp.get(sub)==a.get(sub)){
count--;
}
}
if(time==0){
left++;
right+=w;
}
right++;
}
//s.substring(left,right);
return result;
}
public static void main(String[] args) {
A30 solution = new A30();