Analyze that code "/** * Definition for singly-linked list. * class ListNode { * val:…
- User
Analyze that code "/**
- Definition for singly-linked list.
- class ListNode {
-
code
val: number -
code
next: ListNode | null -
code
constructor(val?: number, next?: ListNode | null) { -
code
this.val = (val===undefined ? 0 : val) -
code
this.next = (next===undefined ? null : next) -
code
} - } */
function mergeInBetween(list1: ListNode | null, a: number, b: number, list2: ListNode | null): ListNode | null { let currentList1 = list1; let currentList2 = list2;
codelet savePoint1; let savePoint2; let i = 0; while (currentList2.next) { currentList2 = currentList2.next; } while (i < b + 1) { currentList1 = currentList1.next; savePoint1 = currentList1; i++; } currentList2.next = currentList1; currentList1 = list1; i = 0; while (i < a - 1) { currentList1 = currentList1?.next; savePoint1 = currentList1; i++; } savePoint1.next = list2; return list1;};" because i have some sort of problem. Leetcode says that "Wrong Answer 58 / 61 testcases passed Input list1 = [0,1,2] a = 1 b = 1 list2 = [1000000,1000001,1000002,1000003] Use Testcase Output Error - Found cycle in the ListNode Expected [0,1000000,1000001,1000002,1000003,2]". Basically most of the testcases passes but i have an edge case which make the list to have a cycle but i don't understand it exactly how.
- Assistant