796. Rotate String
Easy
194788Add to ListShareGiven 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.
- For example, if s = "abcde", then it will be "bcdea" after one shift.
Example 1:
Input: s = "abcde", goal = "cdeab"
Output: true
Example 2:
Input: s = "abcde", goal = "abced"
Output: false
Constraints:
- 1 <= s.length, goal.length <= 100
- s and goal consist of lowercase English letters.
이문제는 약간의 트릭을 사용하여 쉽게 풀수 있다 그 트릭은
s string을 s+s로 하여 s의 원소를 움직여 바꿀수 있는지 확인 할 수 있다.
class Solution {
public:
bool rotateString(string s, string goal) {
return s.size() == goal.size() && (s+s).find(goal)!=string::npos;
}
};
운영중인 카톡방입니다.
C/C++/C# 언리얼/유니티 /질문
#C++#C#언리얼#게임개발#질문#개발#자료구조#백준#프로그래머스#c#유니티#unity#enreal
open.kakao.com
'LeetCode' 카테고리의 다른 글
415. Add Strings 문제 c++ (0) | 2022.07.10 |
---|---|
125. Valid Palindrome 문제 (0) | 2022.07.10 |
28. Implement strStr() c++ (0) | 2022.07.07 |
1. Two Sum Leetcode 문제 (0) | 2022.07.04 |
287. Find the Duplicate Number c++ 문제 풀이 (0) | 2022.07.03 |
댓글