"Programmer interview book", "Programmer interview book"

Source: Internet
Author: User

"Programmer interview book", "Programmer interview book"

[Disclaimer: All Rights Reserved. indicate the source for reprinting. Do not use it for commercial purposes. Contact mailbox: libin493073668@sina.com]


Question link: http://www.nowcoder.com/practice/bc12808a2b0f445c96a64406d5513e96? Rp = 1 & ru =/ta/cracking-the-coding-interview & qru =/ta/cracking-the-coding-interview/question-ranking


Description
Suppose we all know very efficient algorithms to check whether a word is a substring of another string. Compile this algorithm into a function. If two strings s1 and s2 are specified, compile the code to check whether s2 is rotated by s1. You must call the function that checks the substring only once.
Given two strings s1 and s2, return the bool value to indicate whether s2 is rotated by S1. The string contains letters, spaces, and case-sensitive characters. The length of the string is less than or equal to 1000.
Test example:
"Hello world", "worldhello"
Return Value: false
"Waterbottle", "erbottlewat"
Return Value: true

Ideas
For this question, we only need to copy and splice the original string to obtain a new string, and then determine whether the reverse string is a substring of the new string.


Class ReverseEqual {public: bool checkReverseEqual (string s1, string s2) {// write code hereif (s1.length ()! = S2.length () return false; string s3 = s1 + s1; return s3.find (s2 )! =-1 ;}};


Copyright Disclaimer: This article is the original article of the blogger. If it is reproduced, please indicate the source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.