leetcode 14 最长公共前缀
LeetCode 14 最长 公共 前缀
2023-09-27 14:29:24 时间
最长公共前缀
高刷题
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string result;
char tmp;
for (int i=0 ; i <strs[0].size() ; i++)
{
for(int j=0 ; j < strs.size() ; j++)
{
if(i >= strs[j].size()) return result;
if(j==0)
{
tmp = strs[j][i];
continue;
}
if(strs[j][i] != tmp) return result;
}
result += tmp;
}
return result;
}
};
相关文章
- 【LeetCode】计算右侧小于当前元素的个数 [H](归并排序)
- 【LeetCode刷题Java版】Reverse Words in a String
- LeetCode_数学分析_中等_754.到达终点数字
- LeetCode_二叉树_困难_297.二叉树的序列化与反序列化
- LeetCode_动态规划_困难_174.地下城游戏
- leetcode day6 -- String to Integer (atoi) && Best Time to Buy and Sell Stock I II III
- LeetCode-35. 搜索插入位置(Golang实现)
- [LeetCode] 362. Design Hit Counter 设计点击计数器
- [LeetCode] 210. Course Schedule II 课程安排II
- [LeetCode] 21. Merge Two Sorted Lists 合并有序链表
- [LeetCode] 14. Longest Common Prefix 最长共同前缀
- leetcode算法: Find Largest Value in Each Tree Row
- 前端面试必备-40道LeetCode经典面试算法题
- leetcode 27 移除元素