-
Notifications
You must be signed in to change notification settings - Fork 19.9k
Add ReverseWordsInString
#4456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ReverseWordsInString
#4456
Conversation
…e space. Input: s = "the sky is blue" Output: "blue is sky the"
…e space. Input: s = "the sky is blue" Output: "blue is sky the"
src/main/java/com/thealgorithms/strings/ReverseWordInString.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if have some characters like \n
or \t
?
src/main/java/com/thealgorithms/strings/ReverseWordInString.java
Outdated
Show resolved
Hide resolved
src/main/java/com/thealgorithms/strings/ReverseWordInString.java
Outdated
Show resolved
Hide resolved
src/main/java/com/thealgorithms/strings/ReverseWordInString.java
Outdated
Show resolved
Hide resolved
src/test/java/com/thealgorithms/strings/ReverseWordInStringTest.java
Outdated
Show resolved
Hide resolved
added replace all to remove whitespace char from the string, please review |
Could you also add a test case when such operation occurs? |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code loop for ever. The start
is always zero. Maybe your findNextWord
method should return a Pair<Integer, Integer>
where the fist entry is the start
and the second the length of the word (or end
- depends on you, with the end
it is never clear is the end is inclusive or not). You could also have a method called extractWord
taking such pair as an argument. (make sure to import org.apache.commons.lang3.tuple.Pair;
).
In any case: always make sure that all of the CI checks pass.
…hiq/Java into suchi-reverse-word-in-string
Thanks yes fixed the issue, please check |
src/main/java/com/thealgorithms/strings/ReverseWordsInString.java
Outdated
Show resolved
Hide resolved
src/test/java/com/thealgorithms/strings/ReverseWordInStringTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost there!
Uh oh!
There was an error while loading. Please reload this page.