From 872aee5d207f56483f0009a7da66af7e37c9855d Mon Sep 17 00:00:00 2001 From: Hanting Wang <2696801449@qq.com> Date: Mon, 19 Oct 2026 00:36:03 +0800 Subject: [PATCH] Update A30.java --- src/com/hong/www/A30.java | 75 +++++++++++++++------------------------ 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/src/com/hong/www/A30.java b/src/com/hong/www/A30.java index 40d1191..2775106 100644 --- a/src/com/hong/www/A30.java +++ b/src/com/hong/www/A30.java @@ -15,59 +15,40 @@ public class A30 { * } */ public List findSubstring(String s, String[] words) { - /* - * int time=0; - * ArrayList temp = new ArrayList<>(); - * aaa(time,words,temp); - * - * List result = new ArrayList<>(); - * for(String x:words){ - * temp.setLength(0); - * } - */ - char[] a = s.toCharArray(); - HashMap temp = new HashMap<>(); - List result = new ArrayList<>(); - HashSet temp1 = new HashSet<>(); + int left=0; + int right=1; + int w=words[0].length(); + char[] chars=s.toCharArray(); + HashMap a=new HashMap<>(); + HashMap 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 (righta.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)){ + + } + } + left+=w; + } + }else if(temp.get(sub)==a.get(sub)){ + count--; } } - 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); - } - - if(time==0){ - left++; - } - right++; - } - //s.substring(left,right); - return result; + right+=w; + } } public static void main(String[] args) { A30 solution = new A30();