当前位置:网站首页>Longest public prefix of leetcode
Longest public prefix of leetcode
2022-06-24 09:16:00 【SZU healing system bug】
Title Description
Write a function to find the longest common prefix in the string array .
If no common prefix exists , Returns an empty string .
Thought analysis
The longest public prefix is first public , That means everyone has , So we can get a string first , Then compare from beginning to end , That's exactly what it is : Used to take the first one to operate , Compare the first string with the following string , Compare character by character , If you encounter different characters, it means that the same characters have disappeared , It's over , If they are the same , So the longest public is yourself .
AC Code
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
int num=strs.size();
for(int i=0;strs[0][i];i++)
{
for(int j=1;j<num;j++)
{
if(strs[0][i]!=strs[j][i])
return strs[0].substr(0,i);
}
}
return strs[0];
}
};边栏推荐
- When programmers are asked if they can repair computers... | daily anecdotes
- MySQL | store notes of Master Kong MySQL from introduction to advanced
- 110. balanced binary tree recursive method
- 1528. rearrange strings
- Lu Qi: I am most optimistic about these four major technology trends
- MYCAT read / write separation and MySQL master-slave synchronization
- Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
- [ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)
- Numpy NP in numpy c_ And np r_ Explain in detail
- 4275. Dijkstra sequence
猜你喜欢

解决:jmeter5.5在win11下界面上的字特别小

YOLOX backbone——CSPDarknet的实现

MySQL | view notes on Master Kong MySQL from introduction to advanced

The border problem after the focus of input

Ordinary people have no education background. Can they earn more than 10000 yuan a month by Self-taught programming?

Remote connection of raspberry pie without display by VNC viewer

A tip to read on Medium for free
![[noi Simulation Competition] send (tree DP)](/img/5b/3beb9f5fdad00b6d5dc789e88c6e98.png)
[noi Simulation Competition] send (tree DP)

学习太极创客 — ESP8226 (十三)OTA

嵌入式 | 硬件转软件的几条建议
随机推荐
Pytoch read data set (two modes: typical data set and user-defined data set)
A tip to read on Medium for free
On the routing tree of gin
Mba-day25 best value problem - application problem
普通人没有学历,自学编程可以月入过万吗?
每周推荐短视频:计算的终极形态是“元宇宙”?
【LeetCode】541. Reverse string II
2022.06.23 (traversal of lc_144,94145\
Spark - the number of leftouterjoin results is inconsistent with that of the left table
当程序员被问会不会修电脑时… | 每日趣闻
【ES6闯关】Promise堪比原生的自定义封装(万字)
荐书丨《好奇心的秘密》:一个针尖上可以站多少跳舞的小天使?
12、 Demonstration of all function realization effects
Weekly recommended short video: talk about "meta universe" with a serious attitude
【Redis实现秒杀业务①】秒杀流程概述|基本业务实现
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
2138. splitting a string into groups of length k
Ebanb B1 Bracelet brush firmware abnormal interrupt handling
1528. rearrange strings
读CVPR 2022目标检测论文得到的亿点点启发