diff --git a/bfs.java b/bfs.java new file mode 100644 index 0000000..1a37812 --- /dev/null +++ b/bfs.java @@ -0,0 +1,69 @@ +class Solution { + public int orangesRotting(int[][] grid) { + int m=grid.length; + int n=grid[0].length; + Queue q=new LinkedList<>(); + int fresh=0; + int[][] dirs={{-1,0},{0,1},{1,0},{0,-1}}; + for(int i=0;i=0 && pr>=0 && sr subordinates; +}; +*/ + +class Solution { + HashMap map; + public int getImportance(List employees, int id) { + this.map=new HashMap<>(); + for(Employee emp:employees){ + map.put(emp.id,emp); + } + Queue q=new LinkedList<>(); + q.add(id); + int ans=0; + while(!q.isEmpty()){ + int currid=q.poll(); + Employee obj=map.get(currid); + ans+=obj.importance; + for(int subid:obj.subordinates){ + q.add(subid); + } + } + return ans; + } +}