https://leetcode.com/problems/course-schedule-ii/ 问题类似于这个问题,但它输入的是字符串而不是数字。以下是类和示例测试用例和签名。我只是想知道如何处理字符串
的输入import java.util.*;
class Order{
String order = "";
public Order(String string){
this.order = string;
}
}
class OrderDependency{
Order cur;
Order pre;
public OrderDependency(Order o1, Order o2){
cur = o1;
pre = o2;
}
}
public class Order_Dependency {
public static List<Order> getOrderList(List<OrderDependency> orderDependencies){
***Code Starts Here***
}
public static void main(String[] args) {
Order o1 = new Order("A");
Order o2 = new Order("B");
Order o3 = new Order("C");
Order o4 = new Order("D");
OrderDependency od1 = new OrderDependency(o1, o2);
OrderDependency od2 = new OrderDependency(o2, o3);
OrderDependency od3 = new OrderDependency(o3, o4);
List<OrderDependency> list = new ArrayList<>();
list.add(od1);
list.add(od2);
list.add(od3);
for (Order o : getOrderList(list)){
System.out.println(o.order);
}
}
}