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, 只需要 concat s+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)$