当前位置:网站首页>[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.!
边栏推荐
- DigiCert SSL证书支持中文域名申请吗?
- 618 reprise en profondeur: la méthode gagnante de la famille Haier Zhi
- 只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
- Understand one article: four types of data index system
- Digital IC hand tearing code -- voting device
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- Exploration and practice of integration of streaming and wholesale in jd.com
- L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
- Penetration tool - intranet permission maintenance -cobalt strike
- TCP congestion control details | 2 background
猜你喜欢

TCP server communication process (important)

Yolov5 practice: teach object detection by hand

Exploration and practice of integration of streaming and wholesale in jd.com
![[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)](/img/3f/79dcfcd88d779a5d493b4b539bd448.jpg)
[error record] the connection of the flutter device shows loading (disconnect | delete the shuttle/bin/cache/lockfile file)

【Leetcode】14. 最长公共前缀

The macrogenome microbiome knowledge you want is all here (2022.7)
![john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
![john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
随机推荐
Where can I open computer administrator permissions
2322. 从树中删除边的最小分数(异或和&模拟)
What will you do after digital IC Verification?
C语言自定义函数的方法
PCL least median square method fitting plane
IP地址转换地址段
LeetCode 5. 最长回文子串
Method of C language self defining function
LeetCode 1. Sum of two numbers
uboot的作用和功能
一文看懂:数据指标体系的4大类型
Leetcode1380: lucky numbers in matrix
What is normal distribution? What is the 28 law?
[fluent] dart data type boolean type (boolean type definition | logical operation)
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
PWM controlled steering gear
基于多元时间序列对高考预测分析案例
Download blender on Alibaba cloud image station
Global and Chinese markets for airport baggage claim conveyors 2022-2028: technology, participants, trends, market size and share Research Report
How to solve the failure of printer driver installation of computer equipment