Apixio 服務(wù)端工程師面試題
- Redis 和 sql數(shù)據(jù)庫 比較
- 怎樣做到load balance
- 分布式數(shù)據(jù)庫中數(shù)據(jù)庫同時(shí)讀寫怎么防止數(shù)據(jù)不同步
- kafka 和 graphite 實(shí)時(shí)數(shù)據(jù)監(jiān)控是怎么做的?
5.編程題: 從起始點(diǎn)到終點(diǎn)的路徑,附實(shí)現(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);
}
后記: 知識(shí)點(diǎn)還不夠熟,另外,做編程題的時(shí)候,不要老想著leetcode的解答。 自己腦袋里面有思路最關(guān)鍵。我都想到了用hashmap來標(biāo)注訪問過的節(jié)點(diǎn)。沒想到直接用HashSet來標(biāo)注節(jié)點(diǎn)。 面試官都給了很充分的提示了,我當(dāng)時(shí)腦袋停止轉(zhuǎn)動(dòng)了,還沒能搞定。面試官直接給我說了解題思路。估計(jì)是把我掛掉了,我還比較遜色。
同門小師妹都拿到Google nyc的職位了。汗顏! 繼續(xù)努力吧!