3131. Find the Integer Added to Array I Easy
1/**
2 * [3131] Find the Integer Added to Array I
3 *
4 * You are given two arrays of equal length, nums1 and nums2.
5 * Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x.
6 * As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.
7 * Return the integer x.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io" style="
12 * font-family: Menlo,sans-serif;
13 * font-size: 0.85rem;
14 * ">nums1 = [2,6,4], nums2 = [9,7,5]</span>
15 * Output: <span class="example-io" style="
16 * font-family: Menlo,sans-serif;
17 * font-size: 0.85rem;
18 * ">3</span>
19 * Explanation:
20 * The integer added to each element of nums1 is 3.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io" style="
25 * font-family: Menlo,sans-serif;
26 * font-size: 0.85rem;
27 * ">nums1 = [10], nums2 = [5]</span>
28 * Output: <span class="example-io" style="
29 * font-family: Menlo,sans-serif;
30 * font-size: 0.85rem;
31 * ">-5</span>
32 * Explanation:
33 * The integer added to each element of nums1 is -5.
34 * </div>
35 * <strong class="example">Example 3:
36 * <div class="example-block">
37 * Input: <span class="example-io" style="
38 * font-family: Menlo,sans-serif;
39 * font-size: 0.85rem;
40 * ">nums1 = [1,1,1,1], nums2 = [1,1,1,1]</span>
41 * Output: <span class="example-io" style="
42 * font-family: Menlo,sans-serif;
43 * font-size: 0.85rem;
44 * ">0</span>
45 * Explanation:
46 * The integer added to each element of nums1 is 0.
47 * </div>
48 *
49 * Constraints:
50 *
51 * 1 <= nums1.length == nums2.length <= 100
52 * 0 <= nums1[i], nums2[i] <= 1000
53 * The test cases are generated in a way that there is an integer x such that nums1 can become equal to nums2 by adding x to each element of nums1.
54 *
55 */
56pub struct Solution {}
57
58// problem: https://leetcode.com/problems/find-the-integer-added-to-array-i/
59// discuss: https://leetcode.com/problems/find-the-integer-added-to-array-i/discuss/?currentPage=1&orderBy=most_votes&query=
60
61// submission codes start here
62
63impl Solution {
64 pub fn added_integer(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
65 0
66 }
67}
68
69// submission codes end
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn test_3131() {
77 }
78}
79
Back
© 2025 bowen.ge All Rights Reserved.