Question Given the heads of two separately linked lists headA and headB , return the node at which the two lists intersect. If the two linked lists do not intersect at all, return null. For example, the following two linked lists begin to intersect at node c1: Test cases are generated in such a way that there are no loops anywhere in the entire linked structure. Note that linked lists must retain their original structure when the function returns. Own referee: The inputs for the referee are as follows (your program will not receive these inputs): intersectVal - The value of the node where the intersection occurs. This is 0 if there is no intersecting node. listA - The first linked list. listB - Second linked list. skipA - The number of nodes to skip forward in list A (starting from the beginning) to reach the intersected node. skipB - The number of nodes to skip forward in list B (starting from the beginning) to reach the intersecting node. The arbiter then...
C++ | Simplest Way | Brute Force class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { int i = m- 1 , j = n- 1 , index = m+n- 1 ; while (i>= 0 && j>= 0 ){ if (nums1[i]>nums2[j]) nums1[index--] = nums1[i--]; else nums1[index--] = nums2[j--]; } while (i>= 0 ) nums1[index--] = nums1[i--]; while (j>= 0 ) nums1[index--] = nums2[j--]; } };
Comments
Post a Comment