<p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>

<p>Note that an integer is said to be <strong>common</strong> to <code>nums1</code> and <code>nums2</code> if both arrays have <strong>at least one</strong> occurrence of that integer.</p>

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

<pre>
<strong>Input:</strong> nums1 = [1,2,3], nums2 = [2,4]
<strong>Output:</strong> 2
<strong>Explanation:</strong> The smallest element common to both arrays is 2, so we return 2.
</pre>

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

<pre>
<strong>Input:</strong> nums1 = [1,2,3,6], nums2 = [2,3,4,5]
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.
</pre>

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

<ul>
	<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 10<sup>9</sup></code></li>
	<li>Both <code>nums1</code> and <code>nums2</code> are sorted in <strong>non-decreasing</strong> order.</li>
</ul>

class Solution {
public:
    vector<int> dupli(vector<int>& arr) {
    // Sort the array
        sort(arr.begin(), arr.end());

    // Use std::unique to move duplicates to the end
        auto lastUnique = unique(arr.begin(), arr.end());

    // Resize the vector to remove the duplicates
        arr.erase(lastUnique, arr.end());

    return arr;
}
    int getCommon(vector<int>& nums1, vector<int>& nums2) {
        // int n= nums1.size();
        // int m = nums2.size();
        // vector<int> v(m+n,0);
        dupli(nums1);
        dupli(nums2);
        // for(int i=0;i<nums1.size();i++){
        //     v.push_back(nums1[i]);
        // }
        // for(int i=0;i<nums2.size();i++){
        //     v.push_back(nums2[i]);
        // }
        // sort(v.begin(),v.end());
        // for(int i=0;i<v.size();i++){
        //     for(int j=i+1;j<v.size();j++){
        //         if(v[i] == v[j]) return v[i];
        //     }
        // }
        // for (int i = 0; i < nums1.size(); ++i) {
        //     for (int j = 0; j < nums2.size(); ++j) {
        //         if (nums1[i] == nums2[j]) {
        //             return nums1[i]; // Return the first common element
        //         }
        //     }
        // }

        unordered_set<int> set1(nums1.begin(), nums1.end());

        for (int num : nums2) {
            if (set1.find(num) != set1.end()) {
                return num; // Return the first common element
            }
        }

        return -1;
    }
};
71300