来个offer就结束 level
获赞
58
粉丝
1
关注
0
看过 TA
60
门头沟学院
2020
Java
IP属地:北京
暂未填写个人简介
私信
关注
2019-09-21 14:30
已编辑
门头沟学院 Java
0 点赞 评论 收藏
分享
2019-09-18 09:57
已编辑
门头沟学院 Java
难顶
里飞汪汪:同备胎
投递OPPO等公司7个岗位
0 点赞 评论 收藏
分享
2019-09-09 21:36
已编辑
门头沟学院 Java
1、终止进程,过了91%,有点并查集思想       private static int count = 1;     public static void main(String[] args) throws IOException {         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));         String[] pid = bufferedReader.readLine().split(" ");         String...
销声碎:第一题 import java.util.*; public class Main {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         String[] strs = scan.nextLine().split(" ");         int[] pids = new int[strs.length];         for (int i = 0; i < strs.length; i++)             pids[i] = Integer.parseInt(strs[i]);         strs = scan.nextLine().split(" ");         int[] ppids = new int[strs.length];         for (int i = 0; i < strs.length; i++)             ppids[i] = Integer.parseInt(strs[i]);         int n = Integer.parseInt(scan.nextLine());         System.out.println(getNums(pids, ppids, n));     }     static int getNums(int[] pids, int[] ppids, int n) {         HashMap<Integer, List<Integer>> map = new LinkedHashMap<>();         boolean flag = false;         for (int i = 0; i < ppids.length; i++) {             if (pids[i] == n)                 flag = true;             int ppid = ppids[i];             if (map.containsKey(ppid)) {                 List<Integer> tmp = map.get(ppid);                 tmp.add(pids[i]);                 map.replace(ppid, tmp);             } else {                 List<Integer> tmp = new ArrayList<>();                 tmp.add(pids[i]);                 map.put(ppid, tmp);             }         }         if (!flag)             return 0;         if (!map.containsKey(n))             return 1;         return getnum(map, n) + 1;     }     static int getnum(HashMap<Integer, List<Integer>> map, int n) {         if (!map.containsKey(n))             return 0;         List<Integer> list = map.get(n);         int all = list.size();         for (int i = 0; i < list.size(); i++)             all += getnum(map, list.get(i));         return all;     } }
投递奇安信等公司7个岗位
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客网在线编程
牛客网题解
牛客企业服务