-
[LeetCode] 1961. Check If String Is a Prefix of ArrayLeetCode 2021. 10. 15. 16:22728x90
https://leetcode.com/problems/check-if-string-is-a-prefix-of-array/
Check If String Is a Prefix of Array - 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
Check If String Is a Prefix of Array

words 에 있는 단어들을 처음부터 k개를 꺼내 조합하여 s를 만들 수 있는지 묻는 문제이다.
아주 쉽다
비어있는 스트링을 하나 만든뒤, s보다 길이가 작을 경우 words에서 꺼내 붙여준다.
단, words 사이즈를 초과하지 않는지 주의한다.
풀이코드는 아래와 같다.
class Solution { public: bool isPrefixString(string s, vector<string>& words) { string ret = ""; int i=0; while (ret.size()<s.size() && i<words.size()) ret+=words[i++]; return s==ret; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 121. Best Time to Buy and Sell Stock (0) 2021.10.16 [LeetCode] 1869. Longer Contiguous Segments of Ones than Zeros (0) 2021.10.15 [LeetCode] 309. Best Time to Buy and Sell Stock with Cooldown (0) 2021.10.15 [LeetCode] 917. Reverse Only Letters (0) 2021.10.15 [LeetCode] 1695. Maximum Erasure Value (0) 2021.10.14