Skip to content

Commit 9564675

Browse files
committed
update 690.employee-importance.java
1 parent 88f9621 commit 9564675

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

690.employee-importance.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Employee {
5757
*/
5858

5959
class Solution {
60-
public HashMap<Integer, Employee> roster = new HashMap<Integer, Employee>();
60+
public Map<Integer, Employee> roster;
6161

6262
public int getImportance(List<Employee> employees, int id) {
6363
// Given information:
@@ -71,13 +71,16 @@ public int getImportance(List<Employee> employees, int id) {
7171
// Convert List into HashMap
7272
// Nested loops?
7373

74+
// RECURSION - Depth-First Search
7475
// Convert List into HashMap with id as the key
7576
// Store total importance value
7677
// Get root employee
7778
// if root employee has no subordinates
7879
// return importance value
7980
// else, loop over subordinates and recurse down
8081

82+
this.roster = new HashMap<Integer, Employee>();
83+
8184
for (Employee e : employees) {
8285
this.roster.put(e.id, e);
8386
}
@@ -89,7 +92,7 @@ public int calculateImportance(int id) {
8992
Employee lead = this.roster.get(id);
9093
int totalImp = lead.importance;
9194

92-
if (lead.subordinates.size() == 0) {
95+
if (lead.subordinates.isEmpty()) {
9396
return totalImp;
9497
} else {
9598
for (int subId : lead.subordinates) {

0 commit comments

Comments
 (0)