欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

面试精选500题,面试题集锦

终极管理员 知识笔记 33阅读

14. Longest Common Prefixwrote a function to find the longest public prefix string in a string array. If there is no public prefix, the empty string ""is returned. Example 1:Input3360Strs ["flower", "flow", "flight"] Output: "fl" Example 2:Input3360Strs ["dog", "racecar", "car"] Output:" "Explain that there is no common prefix between : input strings. Constraint : 1 strs.length 200 0 strs[i]. The length of 200 strs[i] consists only of lowercase English letters.题目来源Ritter Code II, Solution to Class Solution {public : String LongestCommonPrefix (Vector String Strs) {int n Strs. size (); int count strs[0]。 Length (); for(int I 0; I n-1; i){ int len1 strs[i]。 Length (); int len2 strs[i 1]。 Length (); int tmp 0; for(int j 0; j len1 j len2j){ if(strs[I][j]strs[I 1][j])tmp; Else break} count min (count, tmp); } string resfor(int I 0; I count; (i) Draft resolution [0][ 1]; Return res}};

标签:
声明:无特别说明,转载请标明本文来源!