In leet-code, how to debug javascript code online?

scan leet-code algorithm questions online. Sometimes you don"t know how to debug when something goes wrong. For example, this question:
merging two ordered linked lists

the code template is as follows:

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var mergeTwoLists = function(l1, l2) {
    
};

Test input is

[1,2,4]
[1,3,4]

what is depressing is that it is obvious that L1 and L2 are passed in two arrays, but it seems strange that the code has become an instantiated object of ListNode. Can ListNode be used directly in the code? Write their own code can not run, and can not be debugged online, completely inexplicable!

May.14,2021

isn't there a comment on this?

/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */

just write code according to the type of parameter


it is just displayed on the web page in the form of an array. When it gives you a test in the background, it is naturally a linked list, and self-test is really difficult to test. For linked list questions, you have to new each node to form a linked list

.
Menu