@@ -57,7 +57,7 @@ class Employee {
57
57
*/
58
58
59
59
class Solution {
60
- public HashMap <Integer , Employee > roster = new HashMap < Integer , Employee >() ;
60
+ public Map <Integer , Employee > roster ;
61
61
62
62
public int getImportance (List <Employee > employees , int id ) {
63
63
// Given information:
@@ -71,13 +71,16 @@ public int getImportance(List<Employee> employees, int id) {
71
71
// Convert List into HashMap
72
72
// Nested loops?
73
73
74
+ // RECURSION - Depth-First Search
74
75
// Convert List into HashMap with id as the key
75
76
// Store total importance value
76
77
// Get root employee
77
78
// if root employee has no subordinates
78
79
// return importance value
79
80
// else, loop over subordinates and recurse down
80
81
82
+ this .roster = new HashMap <Integer , Employee >();
83
+
81
84
for (Employee e : employees ) {
82
85
this .roster .put (e .id , e );
83
86
}
@@ -89,7 +92,7 @@ public int calculateImportance(int id) {
89
92
Employee lead = this .roster .get (id );
90
93
int totalImp = lead .importance ;
91
94
92
- if (lead .subordinates .size () == 0 ) {
95
+ if (lead .subordinates .isEmpty () ) {
93
96
return totalImp ;
94
97
} else {
95
98
for (int subId : lead .subordinates ) {
0 commit comments