# My Concise and Self-Understanding Solution base on @jinwu

• ``````public class Solution {
Set<Character> charSet = new HashSet<>();
Map<Character, List<Character>> graph = new HashMap<>();
Map<Character, Integer> indegree = new HashMap<>(); // the number of in degree for each vertex

public String alienOrder(String[] words) {
// first we find all the vertex
getCharSet(words);
for(Character v: charSet) {
graph.put(v, new ArrayList<Character>());
indegree.put(v , 0);
}
// then we build a graph
buildGraph(words);
return  topologicSort(graph); // then topologicSort
}

private void getCharSet(String[] words) {
for (String word : words) {
for (char c : word.toCharArray()) {
}
}
}

private void buildGraph(String[] words) {
for (int i = 0; i < words.length - 1; i++) {
for (int j = i + 1; j < words.length; j++) {
for (int k = 0; k < Math.min(words[i].length(), words[j].length()); k++) {
char first = words[i].charAt(k);
char second =  words[j].charAt(k);
if (first  != second) {

break;
}
}
}
}
}

private String topologicSort(Map<Character, List<Character>> graph) {
for(Character v: graph.keySet()) {
indegree.put(u, indegree.get(u) + 1);
}
}

StringBuffer sb = new StringBuffer();
for(Character c: indegree.keySet()) {
if(indegree.get(c) == 0) {

}
}

while(!q.isEmpty()) {
char v = q.poll();
sb.append(v);
indegree.remove(v);
indegree.put(u, indegree.get(u) - 1);
if(indegree.get(u) == 0) {

}
}
}
if(indegree.keySet().isEmpty()) {
return sb.toString();
} else {
return "";
}

}
}``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.