当前位置:网站首页>leetcode-14. Longest common prefix JS longitudinal scanning method
leetcode-14. Longest common prefix JS longitudinal scanning method
2022-07-06 09:22:00 【Qianfan at the front】
subject
Code
/** * @param {string[]} strs * @return {string} */
// Longitudinal scanning method
var longestCommonPrefix = function(strs) {
let strLen = strs[0].length; // The length of the first element
// Traverse the first element
for (let i = 0; i < strLen; i++) {
let str = strs[0][i];
// Traverse the entire array
for (let j = 0; j < strs.length; j++) {
if (strs[j][i] !== str) {
// If there is a different character , Then exit the loop
return strs[j].slice(0, i);
}
}
}
// End of cycle , Describe each character in the first element of the array , Other elements of the array have ,
// At this point, the first element of the array has been traversed , So this element is the longest common prefix
return strs[0];
};
边栏推荐
- In depth analysis and encapsulation call of requests
- 什么是MySQL?MySql的学习之路是怎样的
- Go redis initialization connection
- Five layer network architecture
- Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
- Post training quantification of bminf
- IDS' deletion policy
- 甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
- Redis' performance indicators and monitoring methods
- Master slave replication of redis
猜你喜欢
Redis之哨兵模式
Intel distiller Toolkit - Quantitative implementation 1
Advanced Computer Network Review(4)——Congestion Control of MPTCP
BN折叠及其量化
Intel Distiller工具包-量化实现3
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
[OC foundation framework] - [set array]
【shell脚本】——归档文件脚本
Le modèle sentinelle de redis
Sentinel mode of redis
随机推荐
Intel distiller Toolkit - Quantitative implementation 2
Kratos战神微服务框架(三)
Redis' performance indicators and monitoring methods
Advance Computer Network Review(1)——FatTree
LeetCode:124. Maximum path sum in binary tree
[oc foundation framework] - < copy object copy >
Post training quantification of bminf
Global and Chinese market of appointment reminder software 2022-2028: Research Report on technology, participants, trends, market size and share
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
[OC]-<UI入门>--常用控件-UIButton
Master slave replication of redis
QML type: overlay
Redis之Bitmap
Redis之Geospatial
Servlet learning diary 7 -- servlet forwarding and redirection
BN folding and its quantification
一文读懂,DDD落地数据库设计实战
CSP student queue
Connexion d'initialisation pour go redis