NC114 旋转字符串

NC114 旋转字符串_第1张图片

public boolean solve (String A, String B) {
        // write code here
        if (A == null || B == null || A.length() < 2 || B.length() < 2 ||
                A.length() != B.length()) {
            return false;
        }
        int i = 1;
        while (i < A.length()) {
            String headStr = A.substring(0, i);
            String tailStr = A.substring(i);
            if (B.contains(headStr) && B.contains(tailStr)) {
                return true;
            }
            i++;
        }
        return false;
    }

你可能感兴趣的:(算法,java,开发语言)