# 0796. Rotate String ###### tags: `Leetcode` `Easy` `String` Link: https://leetcode.com/problems/rotate-string/description/ ## Code ### 思路1 ```java= class Solution { public boolean rotateString(String s, String goal) { return s.length()==goal.length() && (goal+goal).contains(s); } } ``` ### 思路2 ```java= class Solution { public boolean rotateString(String s, String goal) { if(s==null || goal==null) return false; if(s.length()!=goal.length()) return false; if(s.length()==0) return true; for(int i=0; i<goal.length(); i++){ if(rotateMatch(s, goal, i)) return true; } return false; } public boolean rotateMatch(String s, String t, int idx){ for(int i=0; i<s.length(); i++){ if(s.charAt(i)!=t.charAt((i+idx)%s.length())) return false; } return true; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up