gudii9
asked on
pairs challenge improvement
http://codingbat.com/prob/p126332
I wrote as above and passing all steps. Any improvements to my code. please advise
public Map<String, String> pairs(String[] strings) {
Map map=new HashMap();
for(String str:strings){
int len=str.length();
map.put(str.substring(0,1), str.substring(len-1,len));
}
return map;
}
xpected Run
pairs(["code", "bug"]) → {"b": "g", "c": "e"} {"b": "g", "c": "e"} OK
pairs(["man", "moon", "main"]) → {"m": "n"} {"m": "n"} OK
pairs(["man", "moon", "good", "night"]) → {"g": "d", "m": "n", "n": "t"} {"g": "d", "m": "n", "n": "t"} OK
pairs([]) → {} {} OK
pairs(["a", "b"]) → {"a": "a", "b": "b"} {"a": "a", "b": "b"} OK
pairs(["are", "codes", "and", "cods"]) → {"a": "d", "c": "s"} {"a": "d", "c": "s"} OK
pairs(["apple", "banana", "tea", "coffee"]) → {"a": "e", "b": "a", "c": "e", "t": "a"} {"a": "e", "b": "a", "c": "e", "t": "a"} OK
other tests
OK
I wrote as above and passing all steps. Any improvements to my code. 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.