티스토리 뷰

PS

HackerRank. Merge two sorted linked lists

tose33 2023. 10. 19. 14:01

https://www.hackerrank.com/challenges/one-week-preparation-kit-merge-two-sorted-linked-lists/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=preparation-kits&playlist_slugs%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D=one-week-day-five

 

Merge two sorted linked lists | HackerRank

Given the heads of two sorted linked lists, change their links to get a single, sorted linked list.

www.hackerrank.com

 

포인터를 옮기면서 작은 값인쪽을 result 리스트에 넣어주면 된다.

한쪽이 끝까지 도달해서 nullptr 인 경우를 조심해 준다.

 

뭔가 연결리스트 순회 같은거 정확히 구현 기억 안날수도 있는데 주어지는 코드의 print_singly_linked_list() 함수를 보고 하면 된다.

 


아니면 그냥 벡터에 다 넣고 정렬을 한 번더 해줘도 상관없다.

 

'PS' 카테고리의 다른 글

HackerRank. Balanced Brackets  (0) 2023.10.19
HackerRank. Queue using Two Stacks  (0) 2023.10.19
HackerRank. New Year Chaos  (0) 2023.10.19
HackerRank. Recursive Digit Sum  (0) 2023.10.19
백준 15787. 기차가 어둠을 헤치고 은하수를  (0) 2023.10.17
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함