gudii9
asked on
word0 challenge
Hi,
I am working on below challenge.
http://codingbat.com/prob/p152303
i passed all tests. any improvements or alternate approaches? please advise
I am working on below challenge.
http://codingbat.com/prob/p152303
public Map<String, Integer> word0(String[] strings) {
int len=strings.length;
Map<String, Integer> map = new HashMap<String, Integer>();
for(int i=0;i<len;i++){
map.put(strings[i],0);
}
return map;
}
i passed all tests. any improvements or alternate approaches? please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(But I guess compiler optimalisation will do that for you)
Yup, in both cases.
I don't know.
Without that variable, for each iteration of the loop you'll evaluate
strings.length
If you store that value in a variable, you only determine the length once.
(But I guess compiler optimalisation will do that for you)