leetcode

Leetcode Solutions (0x6A73)
git clone https://git.pngu.org/leetcode
Log | Files | Refs | Submodules | README

commit 6acfe62c4bb62dbf5cd70427ae325aa81ac507b5
parent d0c18544f6dd32abe91dff58d341764ce2cf5aee
Author: Jack Sangdahl <jack@pngu.org>
Date:   Tue, 19 May 2026 07:39:54 +0300

2540. minimum common value

Diffstat:
Mmin_common_value.c | 14++++++++------
Mmin_common_value.py | 8++++----
2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/min_common_value.c b/min_common_value.c @@ -43,10 +43,12 @@ int getCommon(int *nums1, int nums1Size, int *nums2, int nums2Size) { } int main() { - int n11[] = {1, 2, 3}, n21[] = {2, 4}, n12[] = {1, 2, 3, 6}, - n22[] = {2, 3, 4, 5}; - printf("%d\n", - getCommon(n11, ARRAY_SIZE(n11), n21, ARRAY_SIZE(n21))); // expect: 2 - printf("%d\n", - getCommon(n12, ARRAY_SIZE(n12), n22, ARRAY_SIZE(n22))); // expect: 2 + int n11[] = {1, 2, 3}, n21[] = {2, 4}; + int n12[] = {1, 2, 3, 6}, n22[] = {2, 3, 4, 5}; + int r1 = getCommon(n11, ARRAY_SIZE(n11), n21, ARRAY_SIZE(n21)); + int r2 = getCommon(n12, ARRAY_SIZE(n12), n22, ARRAY_SIZE(n22)); + printf("%d\n", r1); + assert(r1 == 2); + printf("%d\n", r2); + assert(r2 == 2); } diff --git a/min_common_value.py b/min_common_value.py @@ -12,12 +12,12 @@ occurence of that integer. class Solution(object): def getCommon(self, nums1, nums2): """ - :type nums1: List[int] - :type nums2: List[int] + :type nums1: Lis[int] + :type nums2: Lis[int] :rtype: int """ - st = set(nums1) & set(nums2) - return min(st) if len(st) else -1 + s = set(nums1) & set(nums2) + return min(s) if len(s) else -1 if __name__ == "__main__":