当前位置:网站首页>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; };
边栏推荐
- /Bin/ld: cannot find -lcrypto
- 隐藏在 Nebula Graph 背后的星辰大海
- Add user-defined formula (time sharing t+0) to mobile app access as an example
- Xpt2046 four wire resistive touch screen
- Pyobject to char* (string)
- 手机app通达信添加自定义公式(分时T+0)为例子讲解
- Golang MD5 encryption and MD5 salt value encryption
- 制作p12证书[通俗易懂]
- Strings and arrays
- Armv8-a programming guide MMU (4)
猜你喜欢

华为云服务器安装mysqlb for mysqld.service failed because the control process exited with error code.See “sys

Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points

Armv8-a programming guide MMU (4)

基于 Nebula Graph 构建百亿关系知识图谱实践

Boot transaction usage

可视化技术在 Nebula Graph 中的应用

Processing gzip: stdin: not in gzip format: child returned status 1tar: error is not recoverable: exitin

Idea jar package conflict troubleshooting

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

How to use percona tool to add fields to MySQL table after interruption
随机推荐
Add user-defined formula (time sharing t+0) to mobile app access as an example
Ant group's large-scale map computing system tugraph passed the national evaluation
[idea] recommend an idea translation plug-in: translation "suggestions collection"
多数据源配置代码
Boot transaction usage
Traversal before, during and after binary tree
睿智的目标检测23——Pytorch搭建SSD目标检测平台
Various entanglements between qvariant and Jason -- QT
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量
MySQL calculates the data within the longitude and latitude range
Flink real-time data warehouse (IX): incremental synchronization of data in MySQL
day4
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
[solution] educational codeforces round 82
全是精华的模电专题复习资料:基本放大电路知识点
Tree binary search tree
Add an empty column to spark dataframe - add an empty column to spark dataframe
Pyinstaller打包exe附带图片的方法
What are the necessary functions of short video app development?
使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收