From 8d3e2fe6bfd6f07d18d579692356d1e5af8ac22c Mon Sep 17 00:00:00 2001 From: Shahriar Shatil <52494840+ShatilKhan@users.noreply.github.com> Date: Sat, 9 Mar 2024 12:54:12 +0600 Subject: [PATCH] Time: 65 ms (82.40%) | Memory: 56.8 MB (71.94%) - LeetSync --- .../minimum-common-value.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2634-minimum-common-value/minimum-common-value.js diff --git a/2634-minimum-common-value/minimum-common-value.js b/2634-minimum-common-value/minimum-common-value.js new file mode 100644 index 0000000..bb8121e --- /dev/null +++ b/2634-minimum-common-value/minimum-common-value.js @@ -0,0 +1,20 @@ +/** + * @param {number[]} nums1 + * @param {number[]} nums2 + * @return {number} + */ +var getCommon = function(nums1, nums2) { + let common = Infinity; + let i = 0, j = 0; + while(i < nums1.length && j < nums2.length){ + if(nums1[i] === nums2[j]){ + common = nums1[i]; + break; + }else if (nums1[i] < nums2[j]){ + i++; + }else { + j++; + } + } + return common !== Infinity ? common : -1; +}; \ No newline at end of file