【LeetCode】C# 14、Longest Common Prefix
来源:互联网 发布:美国人性格 知乎 编辑:程序博客网 时间:2024/06/05 02:57
Write a function to find the longest common prefix string amongst an array of strings.
找出字符组中共有的前缀;
建立一个index,直接利用foreach遍历字符组中对应位置的char即可。
public class Solution { public string LongestCommonPrefix(string[] strs) { if(strs.Count() == 0) return ""; if(strs.Count() == 1) return strs[0]; int index = 0; bool x = true; string ret = ""; while(x) { foreach (var item in strs) { if(index >= item.Length || item[index] != strs[0][index]) { x = false; return ret; } } ret += strs[0][index]; index++; }return ret; }}
阅读全文
0 0
- LeetCode #14 Longest Common Prefix C# Solution
- 【LeetCode】C# 14、Longest Common Prefix
- LeetCode 14: Longest Common Prefix
- LeetCode(14) Longest Common Prefix
- LeetCode 14 Longest Common Prefix
- [leetcode 14] Longest Common Prefix
- leetcode 14-Longest Common Prefix
- [leetcode 14] Longest Common Prefix
- [Leetcode] 14 - Longest Common Prefix
- LeetCode | #14 Longest Common Prefix
- leetcode.14----------Longest Common Prefix
- leetCode #14 Longest Common Prefix
- leetcode-14 Longest Common Prefix
- leetcode 14 Longest Common Prefix
- Longest Common Prefix - LeetCode 14
- LeetCode 14 - Longest Common Prefix
- leetcode 14 -- Longest Common Prefix
- Longest Common Prefix leetcode 14
- 全栈者角度--form提交问题(工程下载)
- JAVA IO操作
- idea + maven 使用jedis 连接redis
- 高可用的一些思考和理解
- Tomcat配置 直接用ip访问项目
- 【LeetCode】C# 14、Longest Common Prefix
- Automated Variable Weighting in k-Means Type Clustering
- 数据库管理工具Navicat Premium
- 数据结构:实验二线性表综合实验①顺序表
- gcc/g++参数介绍
- 20、C#里面方法的创建和显示
- android中AlertDialog包含EditText时弹出键盘(dia和软键盘同时弹出)
- Leetcode 169. Majority Element (第四周作业)
- html的几个标签