Java Collection | Set 3 (HashMap) Part-1 Geeks For Geeks
class Solution{
static int map(int n, String keys[], int arr[], String s)
{
HashMap<String,Integer> map1=new HashMap<String,Integer>();
for(int i=0;i<keys.length;i++){
map1.put(keys[i],arr[i]);
}
int val=0;
if(map1.containsKey(s)){
val=map1.get(s);
}
else{
val=-1;
}
return val;
}
}
Time: O(Length of string array or key array) [GFG Time: 0.2/2.2]
Space: O(n)
Thanks for Reading.😇
Comments
Post a Comment