⬆︎
×

[LC] 3131 Find the Integer Added to Array I

Hyplus目录

Java

import java.util.Arrays;

/**
 * <a href="https://leetcode.com/problems/find-the-integer-added-to-array-i/">Find The Integer Added To Array I</a>
 * 数组
 */
class Solution {
    public int addedInteger(int[] nums1, int[] nums2) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        return nums2[0] - nums1[0];
    }
}

C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int addedInteger(vector<int> &nums1, vector<int> &nums2) {
        sort(nums1.begin(), nums1.end());
        sort(nums2.begin(), nums2.end());
        return nums2[0] - nums1[0];
    }
};

发表评论