Skip to content

Commit 5e31e8d

Browse files
check if goal in concatenated s+s
796. Rotate String Solved Easy Topics Companies Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position. For example, if s = "abcde", then it will be "bcdea" after one shift. Example 1: Input: s = "abcde", goal = "cdeab" Output: true Example 2: Input: s = "abcde", goal = "abced" Output: false Constraints: 1 <= s.length, goal.length <= 100 s and goal consist of lowercase English letters. Seen this question in a real interview before? 1/5 Yes No Accepted 492.7K Submissions 786.3K Acceptance Rate 62.7%
1 parent 593eb9a commit 5e31e8d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

boolean-rotate-string.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public boolean rotateString(String s, String goal) {
3+
if(s.length()==goal.length() && (s+s).contains(goal)) return true;
4+
return false;
5+
}
6+
}

0 commit comments

Comments
 (0)