编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。
示例1
输入
["hello","hi","hey"]
输出
"h"
加载中...
import java.util.*; public class Solution { /** * * @param strs string字符串一维数组 * @return string字符串 */ public String longestCommonPrefix (String[] strs) { // write code here } }
class Solution { public: /** * * @param strs string字符串一维数组 * @param strsLen int strs数组长度 * @return string字符串 */ string longestCommonPrefix(string* strs, int strsLen) { // write code here } };
# # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here
/** * * @param strs string字符串一维数组 * @return string字符串 */ function longestCommonPrefix( strs ) { // write code here } module.exports = { longestCommonPrefix : longestCommonPrefix };
# # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here
["hello","hi","hey"]
"h"