ID | Title | Difficulty | |
---|---|---|---|
Loading... |
796. Rotate String
Easy
LeetCode
String, String Matching
Problem
We are given two strings, s and goal.
A shift on s consists of taking string s and moving the leftmost character to the rightmost position. For example, if s = ‘abcde’, then it will be ‘bcdea’ after one shift on s. Return true if and only if s can become goal after some number of shifts on s.
Example 1:
Input: s = 'abcde', goal = 'cdeab'
Output: true
Example 2:
Input: s = 'abcde', goal = 'abced'
Output: false
Code
class Solution {
public boolean rotateString(String s, String goal) {
return s.length() == goal.length() && (s + s).contains(goal);
}
}
按 <- 键看上一题!
795. Number of Subarrays with Bounded Maximum
按 -> 键看下一题!
797. All Paths From Source to Target