Help with optimisation
Hey guys:
Have this code here for the following requirements :
//“Have the function MyLongestString(string[] strings) take an array of strings and return the word that is the longest in length. If there are two or more words with equal length then return the first word. If the array is empty return the string -1”. I really don't like the double if statements I was thinking of using a HashMap but unsure on how to construct it, I mean this is fine but i want to improve. any advice would be great
//“Have the function MyLongestString(string[] strings) take an array of strings and return the word that is the longest in length. If there are two or more words with equal length then return the first word. If the array is empty return the string -1”. I really don't like the double if statements I was thinking of using a HashMap but unsure on how to construct it, I mean this is fine but i want to improve. any advice would be great
5 Replies
wait, what?
it can't be greater and equal at the same time
the second check does nothing
Oh you are so right it can't
hash map doesn't help here
what a blunder
i think i focused on this "!If there are two or more words with equal length then return the first word.!" and just derped
Fixed it, I don't know why i keep trying to overcomplicate simple things, need to knock that bad habbit out of me, thankyou for the catch Anton
you're welcome