当前位置:网站首页>1961 check if string is a prefix of array

1961 check if string is a prefix of array

2022-06-22 12:35:00 Zhou xiansen likes vegetarian food

This series is a new pit opened out of personal interest , Recently I saw my classmates brush LeetCode Algorithm problem , Just want to write those that can be one line Python The title of the code , Therefore, the efficiency of problem-solving methods in this column is not guaranteed , Only for pursuit “ The romance of one line ”.

subject

 Insert picture description here

Answer key

Explain the subject briefly , Given a string s, And a list of strings words, solve s Whether it is words Prefix string ( namely words In front of k Whether or not one can form s). The difficulty of this question is Easy.

Code

The train of thought of this question is relatively simple , Cumulative direct violence against words Before k Splices , See if there is a former k The splicing result of is equal to s, If there is such a k, The output true, Otherwise output false.

class Solution:
    def isPrefixString(self, s: str, words: List[str]) -> bool:
        return sum(map(lambda x: x == s, [''.join(words[:i+1]) for i in range(len(words))])) > 0

The feedback submitted is as follows .
 Insert picture description here

原网站

版权声明
本文为[Zhou xiansen likes vegetarian food]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221154202030.html