Class Solution

java.lang.Object
g2501_2600.s2540_minimum_common_value.Solution

public class Solution extends Object
2540 - Minimum Common Value.<p>Easy</p> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums1 = [1,2,3], nums2 = [2,4]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The smallest element common to both arrays is 2, so we return 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums1 = [1,2,3,6], nums2 = [2,3,4,5]</p> <p><strong>Output:</strong> 2</p> <p><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.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums1[i], nums2[j] <= 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>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • getCommon

      public int getCommon(int[] nums1, int[] nums2)