9.22 阿里笔试第一题
测试用例正确,提交一直0%,求助,哪位大佬帮我看看呗,代码哪里有问题~
题目
代码
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.util.HashSet; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StreamTokenizer st = new StreamTokenizer(br); st.nextToken(); int g = (int)st.nval; for (int z = 0; z < g; z++) { st.nextToken(); int n = (int)st.nval; st.nextToken(); int k = (int)st.nval; if (k > n) { System.out.println(0); } else { int[] in = new int[n]; int[] out = new int[n]; for (int i = 0; i < n; i++) { st.nextToken(); in[i] = (int)st.nval; } for (int i = 0; i < n; i++) { st.nextToken(); out[i] = (int)st.nval; } int count = 0; HashSet<Integer> set = new HashSet<>(); HashSet<Integer> chadui = new HashSet<>(); for (int i = 0; i < k; i++) { set.add(in[i]); } int i = k, j = 0; while (j < n) { if (set.contains(out[j])) { set.remove(out[j]); while (i < n && chadui.contains(in[i])) { i++; } if (i < n) { set.add(in[i]); } } else { count++; chadui.add(out[j]); } i++; j++; } System.out.println(count); } } } }