// "static void main" must be defined in a public class.
public class Main {
public static void main(String[] args) {
int[][] info = new int[4][];
info[0] = null;
info[1] = new int[] {0};
info[2] = new int[] {1};
info[3] = new int[] {1,0};
int[] res = getCourseOrder(info, 3);
for (int i = 0; i<res.length; i++){
System.out.println(res[i]);
} } public static int[] getCourseOrder(int[][]courseInfo, int courseToTake){
List<Integer> list = new ArrayList<>(); Queue<Integer> queue = new LinkedList<>();
Set<Integer> set = new HashSet<>();
queue.add(courseToTake);
while(!queue.isEmpty()){
int course = queue.poll();
list.add(course);
int[] preCourses = courseInfo[course];
if(preCourses != null && preCourses.length>0){
for(int i = 0; i < preCourses.length; i++){
if(!set.contains(preCourses[i])){
queue.add(preCourses[i]);
set.add(preCourses[i]);
} }
}
}
int[] res = new int[list.size()];
for(int i=0; i<list.size(); i++){
res[i] = list.get(list.size() - i -1);
}
return res;
}
}

Microsoft - Get Course Order的更多相关文章

  1. Configure Visual Studio 2013 for debugging .NET framework

    https://referencesource.microsoft.com/ In order to configure Visual Studio 2013 do the following in ...

  2. 第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  3. Tesseract Ocr引擎

    Tesseract Ocr引擎 1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/t ...

  4. Python下Tesseract Ocr引擎及安装介绍

    1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/tesseract,目前最新的源码 ...

  5. 【译】第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  6. DDD实战12 值对象不创建表,而是直接作为实体中的字段

    这里的值对象如下风格: namespace Order.Domain.PocoModels { //订单地址 //虽然是值对象 但是不继承ValueObject //因为继承ValueObject会有 ...

  7. 异常详细信息: System.Security.SecurityException: 未找到源,不过,未能搜索部分或所有事件日志。 若要创建源,您需要用于读取所有事件日志的权限以确保新的源名称是唯一的。 不可访问的日志: Security。

    “/”应用程序中的服务器错误. 安全性异常 说明: 应用程序尝试执行安全策略不允许的操作.要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别. 异常详细信息: Sy ...

  8. C++银行储蓄程序代码

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  9. 【Azure 环境】在Azure虚拟机(经典) 的资源中,使用SDK导出VM列表的办法

    Azure,  在2008年10月的Microsoft专业开发人员大会(PDC)上宣布,当时使用内部项目代号"Project Red Dog",并于2010年2月正式发布为Wind ...

随机推荐

  1. freemarker中对null值问题的处理

    1. freemarker不支持null. 如果值为null会报错. 2.当值为null的处理 1)过滤不显示 Hello ${name!} 在属性后面加感叹号即可过滤null和空字符串 if和”?? ...

  2. android--------阿里 Sophix移动热修复

    移动热修复(Mobile Hotfix)是阿里云提供的全平台App热修复服务方案.产品基于阿里巴巴首创hotpatch技术,提供最细粒度热修复能力,让您无需等待实时修复应用线上问题. 移动热修复提供的 ...

  3. python-day30--粘包

    一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...

  4. zzuli1427 NO.6校赛----数字转换

    1427: 数字转换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 572  Solved: 153 SubmitStatusWeb Board Des ...

  5. POJ-1511 Invitation Cards (双向单源最短路)

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  6. centos6.5升级安装openssl1.0.2h

    最新漏洞通报: Openssl多个漏洞安全预警 2016-05-05 18:05:39 一.概述 在OpenSSL官方昨日(2016/5/3)发布的安全公告中,公开了两个新的高危漏洞CVE-2016- ...

  7. spring的FactoryBean

    (以下内容翻译自spring/docs/3.2.18.RELEASE) 为具有工厂属性的对象实现FactoryBean接口. FactoryBean接口是spring IoC 容器实例化逻辑的一点补充 ...

  8. 在python中是没有NULL的,取而代之的是None,它的含义是为空

    在python中是没有NULL的,取而代之的是None,它的含义是为空

  9. plsql导入excel文件

    plsql导入excel文件   CREATE TABLE     DWSB_GRMX1     (         XH VARCHAR2(40),         SFZH VARCHAR2(40 ...

  10. Instantclient安装

    Instantclient安装 成功