wherehows
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
블로그 내 검색

wherehows

  • 카테고리 없음

    206. Reverse Linked List

    2021. 7. 9.

    by. 창고

    https://leetcode.com/problems/reverse-linked-list/

     

    Reverse Linked List - LeetCode

    Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

    leetcode.com

    in-place로 재정렬 하는 방법.

     

    1->2->3->4->5 로 정렬이 돼있을 때, while문을 들어가기 전, curr은 1을 가리키고, next는 2를 가리키게 한 뒤 while문에 들어간다.

     

    이후부터는 변수가지고 장난치는 것.

     var reverseList = function(head) {
        let prev;
        let curr;
        let next;
    
        curr = head;
        next = head.next;
        curr.next = null;
        while(next) {
            prev = curr;
            curr = next;
            next = curr.next;
            curr.next = prev;
        }
    
        return curr;
    };

    댓글

    맨 위로
전체 글 보기
Tistory 로그인
Tistory 로그아웃
로그아웃 글쓰기 관리

Today

Total

Powered by ⓒ Kakao Corp.

Designed by Nana
블로그 이미지
창고

티스토리툴바