Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. class Solution {
  2.     public boolean rotateString(String A, String B) {
  3.         int len = A.length();
  4.         if (B.length() != len) return false;
  5.         if (len == 0) return true;
  6.        
  7.         for (int shift = 0; shift < len; shift++) {
  8.             boolean failed = false;
  9.             for (int i = 0; i < len; i++) {
  10.                 if (A.charAt(i) != B.charAt((i + shift) % len)) {
  11.                     failed = true;
  12.                     break;
  13.                 }
  14.             }
  15.             if (!failed) {
  16.                 return true;
  17.             }
  18.         }
  19.        
  20.         return false;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement