Redian新闻
>
唉,买个好用的发箍(hair band)真是难啊!
avatar
唉,买个好用的发箍(hair band)真是难啊!# Fashion - 美丽时尚
c*e
1
看题目,应该是传说中的拓扑排序,自己琢磨了一下逻辑,然后Google “拓扑排序”
,发现我的思路就是标准拓扑排序的思路,把没有依赖的都输出了,把剩下依赖它的“
依赖”去掉,直到全部输出,或者,找不到没有依赖的(那就是有循环)为止。下面代
码已提交、接受
有些同学提到深度优先、广度优先,我不太明白是怎么回事?
class Node {
int id; // My course ID
int numOfPre; // How many prerequisites do I have
HashSet preOf; // How many courses have me as prerequisite?

Node(int id){this.id = id; numOfPre = 0; preOf = new HashSet()
;}
void addDependant(Node n){if (!preOf.contains(n)) /*Input has repeat
!*/ {preOf.add(n); n.numOfPre ++;}}
}

public class Solution {
public int[] findOrder(int numCourses, int[][] prerequisites) {
HashMap noPre = new HashMap();
int[][] p = prerequisites;
Node[] all = new Node[numCourses];

// Every course has no prerequisites by default
for (int i = 0; i < numCourses; i ++) {
all[i] = new Node(i);
noPre.put(i, all[i]);
}

// For each a depends on b
for (int i = 0; i < p.length; i ++) {
int a = p[i][0], b = p[i][1];
all[b].addDependant(all[a]);// Record a as b's dependant
noPre.remove(a); // a has prerequisites, so need
remove from the hash map
}

int[] result = new int[numCourses];
int index = 0;

// Output and remove each node in "noPre" since they are all
independant
while (!noPre.isEmpty()) {
Object[] allNoPre = noPre.values().toArray(); // toArray to
avoid iterator on a changing hash map (which is undefined behavior)
noPre.clear();

for (int i = 0; i < allNoPre.length; i++) {
Node n = (Node)allNoPre[i];

result[index] = n.id; index ++;

Object[] allPreOf = n.preOf.toArray();

for (int j = 0; j < allPreOf.length; j ++) {
Node dp = (Node)allPreOf[j];

// Each of n's dependants now has one less prerequisite,
and potentially becomes free (no prerequisites)
if ( (-- dp.numOfPre) == 0)
noPre.put(dp.id, dp);
}
}
}
if (index < numCourses) return new int[0];// Some courses not output
yet, but "noPre" is empty, fail
else return result; // All courses in result,
success
}
}
avatar
d*n
2
是不是过一段时间电脑online也能看到啊?
多谢!
avatar
w*u
3
请问,我是主申请人,我和ld的可以分开交吗?我先交,ld过几个月再交可以吗?是不
是等我的批了以后,ld就不能交了?谢谢
avatar
p*y
4
不知道姐妹们有没有同样的问题。。。
要不就是太紧,箍得我头痛
要不就是老掉,特别是那种细细的一根,我觉得根本没办法戴啊!
橡皮带的那种我更不会用了,还是戴不紧,老掉!!!
难道是我自己的问题?哪个仙女感紧来教教我啊~~~
avatar
n*n
5
太长了

【在 c*******e 的大作中提到】
: 看题目,应该是传说中的拓扑排序,自己琢磨了一下逻辑,然后Google “拓扑排序”
: ,发现我的思路就是标准拓扑排序的思路,把没有依赖的都输出了,把剩下依赖它的“
: 依赖”去掉,直到全部输出,或者,找不到没有依赖的(那就是有循环)为止。下面代
: 码已提交、接受
: 有些同学提到深度优先、广度优先,我不太明白是怎么回事?
: class Node {
: int id; // My course ID
: int numOfPre; // How many prerequisites do I have
: HashSet preOf; // How many courses have me as prerequisite?
:

avatar
d*n
6
amex App怎么加多个账户的offer啊?
avatar
c*r
7
我看过相关的帖子。只要你没变成公民,应该不影响你配偶的485。

【在 w**u 的大作中提到】
: 请问,我是主申请人,我和ld的可以分开交吗?我先交,ld过几个月再交可以吗?是不
: 是等我的批了以后,ld就不能交了?谢谢

avatar
G*e
8
脑袋形状的问题
我跟你一样的
avatar
c*e
9
注释不少
逻辑不多

【在 n******n 的大作中提到】
: 太长了
avatar
z*i
10
多个手机或者pad

【在 d*******n 的大作中提到】
: amex App怎么加多个账户的offer啊?
avatar
b*e
11
我了解到的是
如果结婚日期早于主申请人递交485
-- 主申请人485 pending时,副申请人直接交
-- 主申请人绿卡拿到, 副申请人follow to join
如果结婚日期在主申请人递交485之后
-- 主申请人绿卡approve后,有可能有2-3年排期。不过今年8月份是current,可以直
接交485
avatar
p*y
12
脑袋形状?那就是说我这脑袋就得死了带发箍的心了?555。。。
avatar
b*e
13
可以分开交,没有问题。

【在 w**u 的大作中提到】
: 请问,我是主申请人,我和ld的可以分开交吗?我先交,ld过几个月再交可以吗?是不
: 是等我的批了以后,ld就不能交了?谢谢

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。