当前位置:网站首页>Leetcode --- longest public prefix
Leetcode --- longest public prefix
2022-07-02 16:01:00 【Nanchu】
Title Description
- Write a function to find the longest common prefix in the string array .
- If no common prefix exists , Returns an empty string “”.
- Example 1:
- Input :strs = [“flower”,“flow”,“flight”]
- Output :“fl”
- Example 2:
- Input :strs = [“dog”,“racecar”,“car”]
- Output :""
- explain : Input does not have a common prefix .
How to solve the problem
var longestCommonPrefix = function(strs) { if(strs.length===0){ return ''; } let res=strs[0]; for(let i=0;i<strs.length;i++){ let j=0; for(;j<res.length&&j<strs[i].length;j++){ if(res[j]!=strs[i][j]){ break; } } res=res.substr(0,j); if(res===""){ return res; } } return res; };
边栏推荐
- SQL修改语句
- Fastjson list to jsonarray and jsonarray to list "suggested collections"
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
- 【5G NR】RRC连接释放
- matlab中wavedec2,说说wavedec2函数[通俗易懂]
- Group by的用法
- Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau
- floyed「建议收藏」
- /Bin/ld: cannot find -lcrypto
- 图数据库|Nebula Graph v3.1.0 性能报告
猜你喜欢

Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC

《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究

Recommended practice sharing of Zhilian recruitment based on Nebula graph

Boot transaction usage

Nebula Graph & 数仓血缘关系数据的存储与读写

注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS

Traversal before, during and after binary tree

Idea public method extraction shortcut key

Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit

XPT2046 四线电阻式触摸屏
随机推荐
Construction and business practice of Zhongke brain knowledge map platform
Jsp+mysql006 community management system
Armv8-a programming guide MMU (4)
数组和链表的区别浅析
【题解】Educational Codeforces Round 82
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
制作p12证书[通俗易懂]
matlab中wavedec2,说说wavedec2函数[通俗易懂]
Target detection - make your own deep learning target detection data set with labelimg
(万字精华知识总结)Shell脚本编程基础知识
SQL modification statement
/Bin/ld: cannot find -lssl
lseek 出错
数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
beforeEach
Flink real-time data warehouse (7): Flink realizes the full pull module to extract data in MySQL
仙人掌之歌——投石问路(2)
Digital collection system development (program development) - Digital Collection 3D modeling economic model system development source code
Fiddler realizes mobile packet capturing - getting started