Skip to content
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

Q151 #54

Merged
merged 3 commits into from
Sep 6, 2024
Merged

Q151 #54

merged 3 commits into from
Sep 6, 2024

Conversation

carsonSgit
Copy link
Owner

What is this problem

Given an input string s, reverse the order of the words.

A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

Return a string of the words in reverse order concatenated by a single space.

Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.

How do I solve it

Breakdown:

  1. Reverse the string
  2. Split at white spaces
  3. Append each iterable item + a white space
  4. Return new answer

Resources

Copy link
Owner Author

@carsonSgit carsonSgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# one is so ugly

@carsonSgit carsonSgit merged commit d2659c9 into main Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant