Circular Rotation of String


  • 0
    N

    A string s is a circular rotation of a string t if it matches when the characters are circularly shifted by any number of positions; e.g., ACTGACG is a circular shift of TGACGAC. Write a program that checks whether two given strings s and t are circular shifts of one another. The best solution is a one-liner.


  • 0
    boolean isCircularRotation(String s, String t) {
      return (s + s).indexOf(t) >= 0;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.