728x90
https://leetcode.com/problems/reverse-prefix-of-word/
Reverse Prefix of Word - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
처음부터 ch가 있는 곳까지 reverse 하는 문제
만약 ch가 없다면 바로 word를 그대로 출력
string reversePrefix(string word, char ch) {
size_t index = word.find(ch);
if(index == string::npos) return word;
reverse(word.begin(), word.begin()+index+1);
return word;
}
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/easy/TwoPointer] Check If N and Its Double Exist (0) | 2022.08.17 |
---|---|
[LeetCode/easy/String] Merge Strings Alternately (0) | 2022.08.16 |
[LeetCode/easy/TwoPointer] Find First Palindromic String in the Array (0) | 2022.08.16 |
[LeetCode/easy/Array] Single Number (0) | 2022.08.16 |
[LeetCode/easy/Array] Best Time to Buy and Sell Stock (0) | 2022.08.16 |