Column website www.jiuzhang.com | | nine chapters algorithm

Topic describes

Completes a function that reads a string, reverses the vowels, and returns the reversed string.

Example 1: s = “hello”, return “holle”. Example 2: s = “leetcode”, return “leotcede”.

Analysis of the problem

If you consider a simpler problem: how to invert a string, you’ll immediately think of an algorithm because you know where the characters in each position will appear after the inversion.

In this case, we only need to invert the vowels. Again, we want to know where each vowel should be after the inversion. So we use an array of positions to record the positions of vowels and then reverse them. The algorithm complexity is O(N), where N is the length of the string.

(2) INT two; / / a pointer; One pointer scans from front to back, the other from back to front, and the vowel is swapped until the two Pointers meet and the algorithm terminates. The algorithm is also O(N).

The reference program

Given the time complexity of O(N) (N is the length of a string), the algorithm can advance to the next stage (the interviewer will give more difficult questions).


Recommended reading:

  • Do I need a cover letter to apply online?
  • What are the most popular programming languages of 2017?
  • Top 10 Reasons to Drop an Offer
  • How to negotiate Google Offer? Listen to this Google Recruiter!
  • What about the questions you have done in the interview?
  • Snapchat surface by | LA headquarters interview experience
  • How to learn about an IT company before an interview? Try the official tech blog!
  • The 7 most creative resumes in the history of the Internet
  • Using Twitter to find a job | how to look for job information
  • Facebook +Onsite Onsite Software



Welcome to follow my wechat official account: Ninechapter.



Elite programmer exchange community, regular release of interview questions, interview skills, job information, etc

Nine chapters algorithm, IT education field of deep cultivator