""" 0796.1 - Rotate String - Solution 1 - Brute Force (Check All Rotations) """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def rotateString(self, s: str, goal: str) -> bool:
"""Rotate String Function"""
if len(s) != len(goal):
return False
for i in range(len(s)):
if s[i:] + s[:i] == goal:
return True
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().rotateString("abcde", "cdeab")) # True
print(Solution().rotateString("abcde", "abced")) # False
print(Solution().rotateString("a", "a")) # True
print(Solution().rotateString("aa", "a")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
// 0796 - Runnable implementation
package main
/////////////////////////////////////////////////////////////////////////////////////
// Imports
/////////////////////////////////////////////////////////////////////////////////////
import ("fmt";"sort";"strings")
/////////////////////////////////////////////////////////////////////////////////////
// Solution and Main
/////////////////////////////////////////////////////////////////////////////////////
func solve(s,g string) bool{return len(s)==len(g)&&strings.Contains(s+s,g)}
func main(){fmt.Println(solve("abcde","cdeab"))}
""" 0796.2 - Rotate String - Solution 2 - String Concatenation (Optimal) """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def rotateString(self, s: str, goal: str) -> bool:
"""Rotate String Function"""
return len(s) == len(goal) and goal in s + s
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().rotateString("abcde", "cdeab")) # True
print(Solution().rotateString("abcde", "abced")) # False
print(Solution().rotateString("a", "a")) # True
print(Solution().rotateString("aa", "a")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
// 0796 - Runnable implementation
package main
/////////////////////////////////////////////////////////////////////////////////////
// Imports
/////////////////////////////////////////////////////////////////////////////////////
import ("fmt";"sort";"strings")
/////////////////////////////////////////////////////////////////////////////////////
// Solution and Main
/////////////////////////////////////////////////////////////////////////////////////
func solve(s,g string) bool{return len(s)==len(g)&&strings.Contains(s+s,g)}
func main(){fmt.Println(solve("abcde","cdeab"))}