当前位置:网站首页>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];
};
边栏推荐
- 五层网络体系结构
- Implement window blocking on QWidget
- Redis之发布订阅
- LeetCode41——First Missing Positive——hashing in place & swap
- KDD 2022 paper collection (under continuous update)
- Intel Distiller工具包-量化实现3
- [OC-Foundation框架]---【集合数组】
- Redis之Bitmap
- Connexion d'initialisation pour go redis
- LeetCode41——First Missing Positive——hashing in place & swap
猜你喜欢
Nacos installation and service registration
Intel distiller Toolkit - Quantitative implementation 1
Different data-driven code executes the same test scenario
Advanced Computer Network Review(3)——BBR
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
requests的深入刨析及封装调用
postman之参数化详解
IJCAI2022论文合集(持续更新中)
工作流—activiti7环境搭建
随机推荐
Intel distiller Toolkit - Quantitative implementation 1
自定义卷积注意力算子的CUDA实现
Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
Servlet learning diary 7 -- servlet forwarding and redirection
Global and Chinese market of linear regulators 2022-2028: Research Report on technology, participants, trends, market size and share
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
An article takes you to understand the working principle of selenium in detail
在QWidget上实现窗口阻塞
Intel Distiller工具包-量化实现3
[OC]-<UI入门>--常用控件的学习
Redis' bitmap
Pytest parameterization some tips you don't know / pytest you don't know
Reids之缓存预热、雪崩、穿透
不同的数据驱动代码执行相同的测试场景
SimCLR:NLP中的对比学习
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
Different data-driven code executes the same test scenario
Withdrawal of wechat applet (enterprise payment to change)
运维,放过监控-也放过自己吧
Go redis initialization connection