본문 바로가기
Problem Solving/LeetCode

[LeetCode] 796. Rotate String - Java

by graycode 2026. 10. 15.

• 문제 링크

 

Rotate String - LeetCode

Can you solve this real interview question? Rotate String - 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.

leetcode.com

 

• 풀이 코드

public class Solution {

    public boolean rotateString(String s, String goal) {
        return s.length() == goal.length() && (s + s).contains(goal);
    }

}

댓글