package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
796. Rotate String
Solution idea
- 方法很巧妙,但是不容易想到 (背下来!!!):
- 判断
goal
是不是s
的 rotated string, 只需要 concats+s
, 然后再判断goal
是不是s+s
的substring即可 - The 'shift' operation can be regarded as a 'sliding' operation on
s+s
- 判断
Example:
s = "abcde", goal = "cdeab"
s+s = "abcdeabcde"
s+s = "ab cdeab cde"
goal
Time complexity = $O(n)$