Mỹ Chu Lang
Senior Member
cuối cùng cũng có công ty gọi em đi phỏng vấn sau 2 tháng thất nghiệp giải leetcode
![too_sad :too_sad: :too_sad:](https://data.voz.vn/styles/next/xenforo/smilies/popopo/too_sad.png?v=01)
C#:
public class Solution {
public void DFS (int u, int current, int[][] edges, List<HashSet<int>> tempResult)
{
for(int i = 0; i<edges.Length; i++)
{
if(edges[i][0] == current && !tempResult[edges[i][1]].Contains(u))
{
tempResult[edges[i][1]].Add(u);
DFS(u, edges[i][1], edges, tempResult);
}
}
}
public IList<IList<int>> GetAncestors(int n, int[][] edges) {
List<HashSet<int>> tempResult = new List<HashSet<int>>();
List<IList<int>> result = new List<IList<int>>();
for(int i = 0; i<n; i++)
{
tempResult.Add(new HashSet<int>());
}
for(int i = 0; i<n; i++)
{
DFS(i, i, edges, tempResult);
}
for(int i = 0; i<n; i++)
{
result.Add(tempResult[i].ToList());
}
return result;
}
}