Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string ""
.
Example 1:
Input: ["flower","flow","flight"]Output: "fl"
Example 2:
Input: ["dog","racecar","car"]Output: ""Explanation: There is no common prefix among the input strings.
class Solution {public: string longestCommonPrefix(vector& strs) { int n = strs.size(); if(n == 0) return ""; int k = 0; string ans; bool flag = true; while(true) { // Kst char if(strs[0].size() < k+1) break; char ch = strs[0][k]; for(int i=1; i