majianyu
5/8/2018 - 7:20 AM

Ex1.2.6

回环变位.如果字符串 s 的字符循环移动任意位置后得到另一个字符串 t, 则称 t 为 s 的回环变位. 例如 "ABCDEF" 与 "DEFABC"

func main() {
    fmt.Println(circularRotation("ABCDEF", "DEFABC"))
}
func circularRotation(s, t string) bool {
    return len(s) == len(t) && strings.Contains(s+s, t)
}
def circularRotation(s: str, t: str) -> bool:
    return len(s) == len(t) and t in (s*2)


if __name__ == '__main__':
    print(circularRotation("ABCDEF", "DEFABC"))
public class CircularRotation {
    public static void main(String[] args) {
        System.out.println(circularRotation("ABCDEF", "DEFABC"));
    }

    private static boolean circularRotation(String s, String t) {
        return s.length() == t.length() && s.concat(s).contains(t);
    }
}