当前位置:网站首页>[leetcode] 14. Préfixe public le plus long
[leetcode] 14. Préfixe public le plus long
2022-07-02 17:01:00 【Wangzirui32】
Blogueur wangzirui32
Oui. - Oui. Collection Attention!~~
Cet article a été publié pour la première fois àCSDN,Reproduction interdite sans autorisation
Table des matières
1. Description du sujet

Source::Boucle de force(LeetCode)
Liens:https://leetcode.cn/problems/longest-common-prefix/
Le droit d'auteur est la propriété du réseau de saisie.Pour les réimpressions commerciales, veuillez contacter l'autorisation officielle,Reproduction non commerciale Veuillez indiquer la source.
2. Comment résoudre le problème
Nous avons trouvé la chaîne la plus courte de la liste,Faire un cycle,Chaque boucle vérifie ensuite si elle est identique aux autres préfixes de chaîne,Si le même résultat est stockéresultMoyenne,Renvoie le préfixe maximum après la fin du cycle.
3. Mise en œuvre du Code
Code:
class Solution:
def longestCommonPrefix(self, strs) -> str:
min_length_str = min(strs, key=lambda s: len(s))
result = ""
for i in range(1, len(min_length_str)+1):
swith = min_length_str[:i]
if all([k.startswith(swith) for k in strs]):
result = swith
return result
Je vais analyser le Code le plus important :
min(strs, key=lambda s: len(s))Avec la longueur de la chaîne comme référence , Sélectionner la chaîne minimaleswith = min_length_str[:i]Obtenir l'indexiPréfixe précédentall([k.startswith(swith) for k in strs])Détecter si tous les autres préfixes de chaîne sont identiques .
4. Résultat final

C'est bon,Voici le cours d'aujourd'hui,Je suiswangzirui32,Comme vous pouvez commander une collection et l'attention,À la prochaine fois.!
边栏推荐
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- PWM控制舵机
- Global and Chinese market of desktop hot melt equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- Analysis of how to prevent virus in industrial computer
- Take you ten days to easily complete the go micro service series (I)
- Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
- Method of C language self defining function
- Serial port controls steering gear rotation
- 串口控制舵机转动
- Role and function of uboot
猜你喜欢

Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation

Ap和F107数据来源及处理

Hard core! One configuration center for 8 classes!
![[error record] error -32000 received from application: there are no running service protocol](/img/6c/66099650de46cac88b805e6cfb90b9.jpg)
[error record] error -32000 received from application: there are no running service protocol

如何与博格华纳BorgWarner通过EDI传输业务数据?

DGraph: 大规模动态图数据集

Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes

Leetcode1380: lucky numbers in matrix

Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm

只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
随机推荐
[cloud native] briefly talk about the understanding of flume, a massive data collection component
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
2322. 从树中删除边的最小分数(异或和&模拟)
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
Student course selection system (curriculum design of Shandong Agricultural University)
Global and Chinese markets for airport baggage claim conveyors 2022-2028: technology, participants, trends, market size and share Research Report
Method of C language self defining function
Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
Vscode setting delete line shortcut [easy to understand]
Where can I open computer administrator permissions
lsf基础命令
Learning Weekly - total issue 60 - 25th week of 2022
AcWing 300. Task arrangement
Detailed explanation of @accessories annotation of Lombok plug-in
Cloud native cicd framework: Tekton
【Leetcode】13. 罗马数字转整数
Seal Library - installation and introduction
618深度複盤:海爾智家的制勝方法論
Linux Installation PostgreSQL + Patroni cluster problem