[Algorithm] 33 week(9.12 ~ 9.18) 1/3

Dev_min·2022년 9월 12일
0

algorithm

목록 보기
108/157

876. Middle of the Linked List

var middleNode = function(head) {
    let mid = 0;
    let counter = head;
    
    while(counter.next){
        counter = counter.next;
        mid++;
    }
    
    mid = Math.ceil(mid/2);
    
    while(mid){
        head = head.next;
        mid--;
    }
    
    return head;  
};
profile
TIL record

0개의 댓글