当前位置:网站首页>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; };
边栏推荐
- beforeEach
- /Bin/ld: cannot find -lssl
- [idea] recommend an idea translation plug-in: translation "suggestions collection"
- 数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
- Pyinstaller's method of packaging pictures attached to exe
- Idea public method extraction shortcut key
- Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
- The outline dimension function application of small motherboard
- /Bin/ld: cannot find -lxslt
- In memory of becoming the first dayu200 tripartite demo contributor
猜你喜欢
微信v3native支付设置的结束时间处理办法
idea jar包冲突排查
Figure database | Nepal graph v3.1.0 performance report
中科大脑知识图谱平台建设及业务实践
Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
愛可可AI前沿推介(7.2)
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
Postgressql stream replication active / standby switchover primary database no read / write downtime scenario
手机app通达信添加自定义公式(分时T+0)为例子讲解
随机推荐
Ant group's large-scale map computing system tugraph passed the national evaluation
/bin/ld: 找不到 -lxml2
全方位解读服务网格(Service Mesh)的背景和概念
Usage of group by
/Bin/ld: cannot find -lxml2
Some problems about pytorch extension
Ssh/scp does not prompt all activities are monitored and reported
数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
如何實現十億級離線 CSV 導入 Nebula Graph
Strings and arrays
Idea public method extraction shortcut key
解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau
又是一年毕业季
Boot 连接 Impala数据库
/Bin/ld: cannot find -lcrypto
/Bin/ld: cannot find -lssl
beforeEach
Fiddler realizes mobile packet capturing - getting started
Pyinstaller's method of packaging pictures attached to exe
仙人掌之歌——投石问路(2)