전체 글
-
[못품/릿코드/javascript] 142.Linked List Cycle 2카테고리 없음 2023. 3. 25. 15:15
let s = head, f = head; while(f && f.next && f.next.next){ s = s.next; f = f.next.next; if(s === f){ //주기가 있는지(다시 되돌아가는 포인터가 있는지 확인하는 과정) while(s !== head){ //다시 되돌아가는 포인트를 확인하는 과정 //물이라고 생각하기 병목현상! head = head.next; s = s.next; } return s; } } return null;
-
[못풀었다/javascript/릿코드] merge two sorted lists코딩테스트 2023. 3. 24. 16:15
const mergeTwoLists = (list1, list2) => { // initialize new linked list let head = new ListNode(null) // new pointer let current = head // loop while both lists are not null (did not reach end) while (list1 && list2) { // check which val is lower and point current to it // move the pointer on the lower list if (list1.val { // initialize new linked list let head = new ListNode(null) // new pointe..