当前位置:网站首页>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];
};
边栏推荐
- Intel distiller Toolkit - Quantitative implementation 3
- What is an R-value reference and what is the difference between it and an l-value?
- Redis之Geospatial
- Redis之Lua脚本
- 基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
- Multivariate cluster analysis
- Redis core configuration
- Redis之Bitmap
- Redis之哨兵模式
- Parameterization of postman
猜你喜欢

Blue Bridge Cup_ Single chip microcomputer_ PWM output

【shell脚本】——归档文件脚本

IDS' deletion policy
![[OC]-<UI入门>--常用控件-UIButton](/img/4d/f5a62671068b26ef43f1101981c7bb.png)
[OC]-<UI入门>--常用控件-UIButton

工作流—activiti7环境搭建

Advance Computer Network Review(1)——FatTree

Opencv+dlib realizes "matching" glasses for Mona Lisa

数字人主播618手语带货,便捷2780万名听障人士

Mathematical modeling 2004b question (transmission problem)

Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
随机推荐
Persistence practice of redis (Linux version)
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
BMINF的后训练量化实现
The carousel component of ant design calls prev and next methods in TS (typescript) environment
Redis之主从复制
CUDA实现focal_loss
Global and Chinese market of AVR series microcontrollers 2022-2028: Research Report on technology, participants, trends, market size and share
一篇文章带你了解-selenium工作原理详解
数字人主播618手语带货,便捷2780万名听障人士
Advanced Computer Network Review(5)——COPE
Advance Computer Network Review(1)——FatTree
BN folding and its quantification
Improved deep embedded clustering with local structure preservation (Idec)
Advanced Computer Network Review(3)——BBR
Nacos installation and service registration
Advance Computer Network Review(1)——FatTree
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
go-redis之初始化连接
【每日一题】搬运工 (DFS / DP)