2540. Minimum Common Value Easy
1/**
2 * [2540] Minimum Common Value
3 *
4 * Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.
5 * Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.
6 *
7 * <strong class="example">Example 1:
8 *
9 * Input: nums1 = [1,2,3], nums2 = [2,4]
10 * Output: 2
11 * Explanation: The smallest element common to both arrays is 2, so we return 2.
12 *
13 * <strong class="example">Example 2:
14 *
15 * Input: nums1 = [1,2,3,6], nums2 = [2,3,4,5]
16 * Output: 2
17 * Explanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= nums1.length, nums2.length <= 10^5
23 * 1 <= nums1[i], nums2[j] <= 10^9
24 * Both nums1 and nums2 are sorted in non-decreasing order.
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/minimum-common-value/
30// discuss: https://leetcode.com/problems/minimum-common-value/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn get_common(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_2540() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.