<p>Write a function to find the longest common prefix string amongst an array of strings.</p>

<p>If there is no common prefix, return an empty string <code>&quot;&quot;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;flower&quot;,&quot;flow&quot;,&quot;flight&quot;]
<strong>Output:</strong> &quot;fl&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;dog&quot;,&quot;racecar&quot;,&quot;car&quot;]
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> There is no common prefix among the input strings.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= strs.length &lt;= 200</code></li>
	<li><code>0 &lt;= strs[i].length &lt;= 200</code></li>
	<li><code>strs[i]</code> consists of only lowercase English letters.</li>
</ul>

class Solution {
public:
    string CommonPrefix(string strs1, string strs2) {
        string ans = "";
        int i;
        for (i = 0; i < min(strs1.size(),strs2.size()); i++) {
            if (strs1[i] != strs2[i]) {
                break;
            }
        }
        ans = strs1.substr(0, i );
        return ans;
    }

    string LongestPrefix(vector<string>& strs, int start, int end) {
        if(start==end){
            return strs[start];
        }
        int mid = (start + end) / 2;

        string strs1 = LongestPrefix(strs, start, mid);
        string strs2 = LongestPrefix(strs, mid + 1, end);

        return CommonPrefix(strs1, strs2);
    }

    string longestCommonPrefix(vector<string>& strs) {
        std::ios_base::sync_with_stdio(false);

  std::cout.tie(nullptr);

  std::cin.tie(nullptr);

        return LongestPrefix(strs, 0, strs.size()-1);
    }
};
15600