8.31广联达软件笔试第一题子弹
import java.util.HashSet; import java.util.Scanner; import java.util.Set; /** * @author bty * @date 2022/8/31 * @since 1.8 **/ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] shootOrder = new int[n + 1]; int[] receiveOrder = new int[n + 1]; for (int i = 1; i <= n; i++) { int number = in.nextInt(); shootOrder[i] = number; } for (int i = 1; i <= n; i++) { int number = in.nextInt(); receiveOrder[i] = number; } int left = 1; int right = 1; Set<Integer> broken = new HashSet<>(); while (right <= n && left <= n) { int tar = shootOrder[left]; if (broken.contains(tar)) { left++; continue; } int cur = receiveOrder[right]; if (tar == cur) { left++; right++; continue; } broken.add(cur); right++; } System.out.println(broken.size()); } }
#广联达#