We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That's pretty much the same result that I came up with. One little tweak you can make in your for loop to make it tighter is that you only need to know that i is not greater than j. For words with an odd number of characters, when i == j, that's your midpoint, so you don't have to do the math. For words with even number charactesr, i < j is the middle two characters. In your next loop, i will be greater than j, so you break. Here's the result:
The Love-Letter Mystery
You are viewing a single comment's thread. Return to all comments →
That's pretty much the same result that I came up with. One little tweak you can make in your for loop to make it tighter is that you only need to know that i is not greater than j. For words with an odd number of characters, when i == j, that's your midpoint, so you don't have to do the math. For words with even number charactesr, i < j is the middle two characters. In your next loop, i will be greater than j, so you break. Here's the result: