当前位置:网站首页>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

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 .
边栏推荐
猜你喜欢
随机推荐
uboot do_load函数分析
Find all prime numbers between 100 and 200
OpenCV调用usb摄像头出现“select timeout”解决方法
第十二届 蓝桥杯 嵌入式设计与开发项目 决赛
Flutter version Parallax effect of Zhihu list
access_token不到两个小时失效的处理办法
V4L2像素格式及其对应的含义
Flutter動畫入門: 內外逆向環Loading動畫
Flutter:剥离StatefulWidget——简化页面开发、跳转以及传值
When the tiflash function is pushed down, it must be known that it will become a tiflash contributor in ten minutes
Flutter——ListView源码分析之child-view的构建
PyCharm编写shell脚本无法运行
Flutter - realize progressive card switching of Netease cloud music
Flutter混合开发练习——Evenet&Method Channel协作加载大图
SQL函数——将一对多关系转换成一对一关系
Opencv invokes the USB camera to solve the "select timeout" problem
2022-6-21OS复习成组链接法
TIS教程01-安装
论文解读——Temporal Recommendation on Graphs via Long- and Short-term Preference Fusion
oracle游标









