Apixio 服務(wù)端工程師面試題
- Redis 和 sql數(shù)據(jù)庫 比較
- 怎樣做到load balance
- 分布式數(shù)據(jù)庫中數(shù)據(jù)庫同時讀寫怎么防止數(shù)據(jù)不同步
- kafka 和 graphite 實時數(shù)據(jù)監(jiān)控是怎么做的?
5.編程題: 從起始點到終點的路徑,附實現(xiàn)方法
/*
# Bounded region of a graph that connects 's' to 'e' defined in terms of all
# paths between 's' and 'e'. 's' can have incoming links and 'e' can have
# outgoing edges. The graph can have cycles in it. Each node has at most two
# outgoing edges. Additional data-structures and methods may be defined.
# Do not add new variables in the Node.
# Node has hashCode and equals defined.
# +---+ +---+
# +---->| g |<--------+ k +---------+
# | +-+-+ +---+ |
# | +---+ | | ^ |
#--+-->| s +--+ | | |
# +-+-+ v | v ^
# | +---+ | +---+ |
# +--------->| |-----------+-------->| e +-------+-->
#
+---+ +---+
*/
public class Node {
public Node left;
public Node right;
public int data;
}
public class BoundedGraph {
public Node s;
public Node e;
public BoundedGraph(Node s, Node e) {
this.s = s;
this.e = e;
}
public void printGraph() {
Set<Node> visited = new HashSet<Node>();
innerPrintGraph(s, e, visited);
}
private void innerPrintGraph(Node s, Node e, Set<Node> visited) {
if (visited.contains(s)) return;
System.out.println(s.data);
visited.add(s);
if (s.left != null && s != e)
innerPrintGraph(s.left, e, visited);
}
后記: 知識點還不夠熟硕糊,另外舰讹,做編程題的時候邓馒,不要老想著leetcode的解答阱州。 自己腦袋里面有思路最關(guān)鍵模捂。我都想到了用hashmap來標(biāo)注訪問過的節(jié)點班缰。沒想到直接用HashSet來標(biāo)注節(jié)點贤壁。 面試官都給了很充分的提示了,我當(dāng)時腦袋停止轉(zhuǎn)動了埠忘,還沒能搞定脾拆。面試官直接給我說了解題思路。估計是把我掛掉了莹妒,我還比較遜色名船。
同門小師妹都拿到Google nyc的職位了。汗顏旨怠! 繼續(xù)努力吧渠驼!