当前位置:网站首页>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; };
边栏推荐
- Pyinstaller's method of packaging pictures attached to exe
- Moveit 避障路径规划 demo
- 手机app通达信添加自定义公式(分时T+0)为例子讲解
- How to import a billion level offline CSV into Nepal graph
- Armv8-a programming guide MMU (4)
- Fiddler realizes mobile packet capturing - getting started
- Solve the problem of base64encoder error
- 基于 Nebula Graph 构建百亿关系知识图谱实践
- Traversal before, during and after binary tree
- Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
猜你喜欢

GraphX 图计算实践之模式匹配抽取特定子图

Recommended practice sharing of Zhilian recruitment based on Nebula graph

Write your own CPU Chapter 11 - learning notes

手机app通达信添加自定义公式(分时T+0)为例子讲解

Traversal before, during and after binary tree

HMS core machine learning service helps zaful users to shop conveniently

Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
![[5g NR] RRC connection release](/img/f3/a03f5124493b1c03e7336c55871330.png)
[5g NR] RRC connection release

Register as a harmonios developer and install deveco studio 3.0 beta2 for harmonios

Application of visualization technology in Nebula graph
随机推荐
Construction and business practice of Zhongke brain knowledge map platform
Demo of converting point cloud coordinates to world coordinates
Make p12 certificate [easy to understand]
数据湖(十一):Iceberg表数据组织与查询
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
Boot 中bean配置覆盖
Introduction to database system Chapter 1 short answer questions - how was the final exam?
fastjson List转JSONArray以及JSONArray转List「建议收藏」
idea 公共方法抽取快捷键
SQL FOREIGN KEY
【idea】推荐一个idea翻译插件:Translation「建议收藏」
SQL修改语句
(5) Flink's table API and SQL update mode and Kafka connector case
Idea jar package conflict troubleshooting
beforeEach
The sea of stars hidden behind the nebula graph
基于 Nebula Graph 构建百亿关系知识图谱实践
可视化技术在 Nebula Graph 中的应用
/Bin/ld: cannot find -llz4
又是一年毕业季